Skip to content
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

/usr/lib/sysimage/libdnf5/nevras.toml empty after <ctrl-c> #1753

Open
kontura opened this issue Oct 3, 2024 · 2 comments
Open

/usr/lib/sysimage/libdnf5/nevras.toml empty after <ctrl-c> #1753

kontura opened this issue Oct 3, 2024 · 2 comments
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take

Comments

@kontura
Copy link
Contributor

kontura commented Oct 3, 2024

I was running: while true; do sudo dnf5 install -y ./htop-3.3.0-1.fc39.x86_64.rpm; sudo dnf5 remove htop -y; done to debug a different issue and after hitting <ctrl-c> /usr/lib/sysimage/libdnf5/nevras.toml ended up empty.
Following runs resulting in:

Loading system state TOML file /usr/lib/sysimage/libdnf5/nevras.toml failed (see dnf5-system-state(7)): [error] key "version" not found in the top-level table
 --> /usr/lib/sysimage/libdnf5/nevras.toml
   |
 1 |
   |  the parsed file is empty

It likely requires "lucky" timing.

@ppisar
Copy link
Contributor

ppisar commented Oct 4, 2024

The file is written in State::save() by this code:

utils::fs::File(get_nevra_state_path(), "w").write(toml_format(make_top_value("nevras", nevra_states)));

The flaw is in libdnf5::utils::fs::File class. It directly writes to the named file instead of writing to a temporary file and then atomically renaming it to the given name.

@ppisar ppisar added Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take labels Oct 4, 2024
@ppisar
Copy link
Contributor

ppisar commented Oct 4, 2024

Atomically replacing a file might not be enough: State::save() writes into many files. An interruption could leave half of the files fully updated and the other half fully outdated. One would have to atomically replace whole directory (which is not portably supported by all file systems), or preserve old new new generation of the files in parallel so that next-excuted DNF can rollback when it discovers an unfinished update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: MEDIUM Triaged Someone on the DNF 5 team has read the issue and determined the next steps to take
Projects
Status: Backlog
Development

No branches or pull requests

2 participants