No longer allow overriding the frozen attribute of containers#10499
Merged
No longer allow overriding the frozen attribute of containers#10499
Conversation
The Array, Dictionary, and Namespace types provide a Freeze() method that makes them read-only. So far, there was the possibility to call some methods with `overrideFrozen=true` which would then bypass the corresponding check and allow modification of the data structures nonetheless. With 24b57f0, this possibility was already removed from the Namespace type. However, for interface compatibility, it kept the parameter and just ignores it, throwing an exception on any modification on a frozen instance. The only place using `overrideFrozen` was processing of the `-D`/`--define` command line flag that allows setting additional variables in the DSL. At the time it is evaluated, there are no user-created data structures yet that could be frozen, so the only frozen objects that could be encountered are Namespaces (Icinga doesn't freeze other types by itself) and for these, `overrideFrozen` already has no effect. Hence, there is no harm in removing `overrideFrozen` altogether. This simplifies the code and also means that frozen objects are now indeed read-only without exceptions, allowing further optimizations regarding locking in the future.
yhabteab
approved these changes
Jul 8, 2025
Member
yhabteab
left a comment
There was a problem hiding this comment.
$ grep --exclude-dir=build --exclude-dir=prefix --exclude-dir=doc -niR 'overrideFrozen' .
<nothing>Config package updates (director):
...
[2025-07-08 15:37:18 +0200] information/ApiListener: New client connection from [::1]:52531 (no client certificate)
[2025-07-08 15:37:18 +0200] information/ConfigPackageUtility: Updating configuration file: /Users/yhabteab/Workspace/icinga2/prefix/var/lib/icinga2/api/packages/example-cmdb/dc8d5503-71a4-4498-9c8b-637e99bd06c1/conf.d/test.conf
[2025-07-08 15:37:18 +0200] information/HttpServerConnection: Request POST /v1/config/stages/example-cmdb (from [::1]:52531, user: root, agent: curl/8.7.1, status: OK) took total 1ms.
[2025-07-08 15:37:18 +0200] information/HttpServerConnection: HTTP client disconnected (from [::1]:52531)
[2025-07-08 15:37:20 +0200] information/Application: Got reload command: Starting new instance.
...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Array, Dictionary, and Namespace types provide a Freeze() method that makes them read-only. So far, there was the possibility to call some methods with
overrideFrozen=truewhich would then bypass the corresponding check and allow modification of the data structures nonetheless.With #9627 (24b57f0), this possibility was already removed from the Namespace type. However, for interface compatibility, it kept the parameter and just ignores it, throwing an exception on any modification on a frozen instance.
The only place using
overrideFrozenwas processing of the-D/--definecommand line flag that allows setting additional variables in the DSL. At the time it is evaluated, there are no user-created data structures yet that could be frozen, so the only frozen objects that could be encountered are Namespaces (Icinga doesn't freeze other types by itself) and for these,overrideFrozenalready has no effect.Hence, there is no harm in removing
overrideFrozenaltogether. This simplifies the code and also means that frozen objects are now indeed read-only without exceptions, allowing further optimizations regarding locking in the future. In particular, #10414 currently assumes that frozen Arrays/Dictionaries can be iterated without holding (which is only true as long as there is no operation withoverrideFrozen).Tests
Because of the following, I don't expect any observable difference in behavior from this change:
I've tested that Icinga 2 still starts with this changes and works in general. Additionally, I've also successfully tested a config deployment from Director (as that's a case that makes use of
--define).