Skip to content

Reduce risk of an interrupted installation leading to a partial installation - #2261

Merged
Gankra merged 5 commits into
axodotdev:mainfrom
EliteTK:reduce-interruption-risk
Feb 20, 2026
Merged

Gankra merged 5 commits into
axodotdev:mainfrom
EliteTK:reduce-interruption-risk

Conversation

@EliteTK

@EliteTK EliteTK commented Jan 21, 2026 •

Copy link
Copy Markdown
Contributor

Since the installer script uses mktemp -d to create a directory to store the downloaded release and extract it, the files might end up on a different filesystem than the target installation directory. This means that the mv basically turns into a cp followed by an rm which means that if it gets interrupted at this point, the result could be a partially written file, or just in general an installation with only some of the files written.

There's no real way to solve this without support from the filesystem, so instead this PR aims to reduce the window in these cases by first using mv to copy/move the files into a subdirectory of the target and then mv the files out. The second round of mv should just be rename under the hood so this should happen quickly. As an additional side effect, while you might end up with a partial upgrade, you will never end up with a partially written binary.

Also, since the temporary directory creation was successful, this means that the final round of mv is likely to also be successful as both require the same permissions to the parent directory.

@EliteTK
EliteTK force-pushed the reduce-interruption-risk branch from b40cdc9 to 3d4e033 Compare January 30, 2026 09:11
@EliteTK
EliteTK marked this pull request as ready for review January 30, 2026 09:12
@EliteTK
EliteTK force-pushed the reduce-interruption-risk branch 2 times, most recently from d472e48 to 6b19e24 Compare February 20, 2026 11:22

@Gankra Gankra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall approach makes total sense to me, good call.

Comment on lines +697 to +701
for _bin_name in $_bins; do
ensure mv "$_install_temp/$_bin_name" "$_install_dir"
for _dest in $(aliases_for_binary "$_bin_name" "$_arch"); do
ln -sf "$_install_dir/$_bin_name" "$_install_dir/$_dest"
done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here got doubled compared to the rest of the file

ensure mkdir -p "$_install_dir"
ensure mkdir -p "$_lib_install_dir"
_install_temp=$(mktemp -d "$_install_dir/tmp.XXXXXXXXXX")
_lib_install_temp=$(mktemp -d "$_lib_install_dir/tmp.XXXXXXXXXX")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unfortunate that we unconditionally do this, even in the common case (all of astral) where there's no libs to install.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a lot of unconditional stuff which isn't needed for our stuff. I was thinking of contributing something to clear that up. Do you want me to add a commit which removes the lib stuff when there are no libs? It shouldn't be difficult, except for the tests - I wouldn't know where to start with those...

_test_blake2s="$(printf "can do blake2s" | b2sum -a blake2s | awk '{printf $1}')" || _test_blake2s=""

if [ "X$_test_blake2s" = "X$_well_known_blake2s_checksum" ]; then
if [ "$_test_blake2s" = "$_well_known_blake2s_checksum" ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I added a shellcheck ignore in my PR because I didn't want to think about if this is indeed safe to drop on all our supported platforms (if you have a strong sense I'm happy to land this).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most recent shell which fixed the bug that this tries to work around is zsh which I don't think anyone uses as their /bin/sh implementation (mac uses bash for it). They fixed in 2015.

Dash fixed it in 2008 and bash fixed in 1995.

That being said, now that I've given this a second glance, I think there's a trivial way to make it so it doesn't matter. We can just swap the arguments and put "_well_known_blake2s_checksum" first. That is controlled by the generator so it won't start with a leading - (assuming it continues to be a blake2 hash).

EliteTK and others added 4 commits February 20, 2026 12:34
This defers moving the new files until after they're definitely on the
same filesystem as the target directory to reduce the window during
which an interrupted installation could cause a partial update.
@EliteTK

EliteTK commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

I couldn't figure out how to run the _basic test and wasn't sure if there was a snapshot for it. I'll try to get it working or manually edit the snapshots.

@Gankra
Gankra force-pushed the reduce-interruption-risk branch from 6b19e24 to 42c1dce Compare February 20, 2026 17:37
@Gankra

Gankra commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Yeah I discovered this week that the basic test is subject to some unfortunate bitrot, the only way to run it is to install exactly this copy of omnibor:

https://github.com/axodotdev/cargo-dist/blob/main/.github/workflows/ci.yml#L124

(I should rip out the omnibor stuff if it doesn't even work...)

@mistydemeo

Copy link
Copy Markdown
Contributor

I was checking GitHub and it looks like at least one project out there is using the omnibor support. It's unfortunate they changed the CLI options in a backwards-incompatible way; makes it harder for us to support older and newer versions.

@Gankra
Gankra merged commit 12c4aac into axodotdev:main Feb 20, 2026
17 checks passed
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.

3 participants