Skip to content

Fix thread unsafety due to internal use of set_var() #84

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

Merged
merged 1 commit into from
Aug 3, 2025

Conversation

delan
Copy link
Contributor

@delan delan commented Aug 3, 2025

this is the first of two patches aimed at addressing thread safety issues. set_debug() and set_pipefail() change the debug and pipefail settings by using std::env::set_var(), which is now known to be unsafe to use in multi-threaded programs. note that the unsafety is not because it has global effect when it works as intended (this will be addressed in the second patch), but rather that it may not work as intended if other threads are reading from the environment.

this patch reworks set_debug() and set_pipefail() to write to a LazyLock<AtomicBool> variable for that setting. these variables read from the environment variables on first use. this is technically a breaking change, because consumers may have relied on changing these settings with std::env::set_var(), but such consumers were incorrect anyway.

i’ve also updated the docs for thread safety issues and global state to improve their accuracy.

@tao-guo tao-guo merged commit 171690e into rust-shell-script:master Aug 3, 2025
1 check passed
@delan delan deleted the fix-thread-unsafety branch August 3, 2025 03:46
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.

2 participants