Skip to content

test flake: fbuild-paths tests read HOME while env-guard tests call set_var/remove_var concurrently #1483

Closed

Description

@zackees

Seen while validating #1431. soldr cargo test -p fbuild-paths --lib intermittently fails, about 1 run in 3 locally:

thread 'tests::other_fbuild_root_is_opposite_mode' panicked at crates/fbuild-paths/src/lib.rs:47:27:
could not determine home directory

HOME is set in the environment and no test removes it. The env-guard helpers in crates/fbuild-paths/src/running_process.rs (ENV_LOCK, lines 268–293) and dev_daemon_namespace.rs (lines 103–132) call std::env::set_var / remove_var on other variables under their own lock. The lib.rs tests (for example other_fbuild_root_is_opposite_mode → get_fbuild_root() → dirs_next()) read HOME without taking that lock. On glibc, setenv racing with getenv in another thread is unsound: getenv can see a transiently reallocated environ and return NULL. That's why set_var is unsafe in newer editions.

Fix options:

  • Have every test that reads the process environment in this crate take one shared env lock.
  • Or make the env-mutating tests not mutate the real process environment, by injecting the values instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions