Skip to content

Draft: Bug in Variable handling #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adriaan42
Copy link
Contributor

While working on #758, I noticed a bug in the way variables are handled:

Currently, there is one global Variables object, as member of the global Application. When loading profiles, variables are added to it, but never removed. So when switching profiles, there are still variables present from the previous profile.

To demonstrate, use the debug print from the first commit of this PR, with two profiles:

  • Profile variable1:
    [variables]
    foo=42
  • Profile variable2:
    [variables]
    bar=23

Then use tuned-adm profile to switch between them, and note how the debug output will contain not only variables of the current, but also of the previously loaded profile:

[... started with profile variable1 active ...]
2025-03-10 08:58:57,683 INFO     tuned.profiles.loader: loading profile: variable1
2025-03-10 08:58:57,688 DEBUG    tuned.daemon.daemon: BUG: variables=dict_keys(['(?<!\\\\)\\${foo}'])
2025-03-10 08:58:57,688 INFO     tuned.daemon.daemon: starting tuning
[... tuned-adm profile variable2 ...]
2025-03-10 08:59:21,570 INFO     tuned.profiles.loader: loading profile: variable2
2025-03-10 08:59:21,571 DEBUG    tuned.daemon.daemon: BUG: variables=dict_keys(['(?<!\\\\)\\${foo}', '(?<!\\\\)\\${bar}'])
2025-03-10 08:59:21,571 INFO     tuned.daemon.daemon: starting tuning

My proposal is to have the Variables object owned by the Profile. It is created by the profile loader, so that more complex load scenarios (multiple profiles, potentially with includes) still only use one Variables object.

An alternative would be to simply clear variables when loading a new profile, but that would break my #758, where (when restoring a snapshot) a second profile is loaded, which can fail, and therefore does not work well with Variables as global state.

Currently, there is one global Variables object, as member of the global
Application. When loading profiles, variables are added to it, but never
removed. So when switching profiles, there are still variables present
from the previous profile.
With this commit, the Variables object is now owned by the Profile.
It is created by the profile loader, so that more complex laod scenarios
(multiple profiles, potentially with includes) still only use one Variables
object.

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant