Skip to content

Fix macOS tmpdir cleanup race caused by system daemons creating ~/Library#3515

Open
sean- wants to merge 1 commit intothought-machine:masterfrom
sean-:fix-macos-tmpdir-cleanup
Open

Fix macOS tmpdir cleanup race caused by system daemons creating ~/Library#3515
sean- wants to merge 1 commit intothought-machine:masterfrom
sean-:fix-macos-tmpdir-cleanup

Conversation

@sean-
Copy link
Copy Markdown
Contributor

@sean- sean- commented Apr 1, 2026

On macOS, system daemons (cfprefsd, lsd) automatically create $HOME/Library/ for any process whose HOME they observe. Since the build env sets HOME=tmpDir, these daemons can recreate Library/ inside a target's temporary directory during or just after cleanup, causing os.RemoveAll to fail with ENOTEMPTY.

Handle this with a platform-specific cleanTmpDir that detects the Library/ directory on ENOTEMPTY and retries removal with bounded backoff. Non-Darwin platforms get a zero-overhead passthrough.

Without this, building plz on macOS would result in output like:

[snip]
Messages:
15:00:16.029 WARNING: Failed to remove temporary directory for //src/fs:_fs_test#modinfo: unlinkat plz-out/tmp/src/fs/_fs_test#modinfo._build: directory not empty
15:00:33.455 WARNING: Failed to create cache directory /Users/sean/Library/Caches/please/third_party/go/_std#srcs/Q5JCAr0UcVqFPYe2uwoh6JPawUY=: rename /Users/sean/Library/Caches/please/third_party/go/_std#srcs
/Q5JCAr0UcVqFPYe2uwoh6JPawUY== /Users/sean/Library/Caches/please/third_party/go/_std#srcs/Q5JCAr0UcVqFPYe2uwoh6JPawUY=: file exists
15:01:15.399 WARNING: Failed to setup cache directory: unlinkat /Users/sean/Library/Caches/please/third_party/go/std/Pnp1rXnQL2Z78LQJ3bPhTXFeIu0==/std/pkg/darwin_amd64/crypto: directory not empty

Which, while harmless, is not helpful for developers starting to use plz.

@sean- sean- force-pushed the fix-macos-tmpdir-cleanup branch from e9d5f81 to f507195 Compare April 1, 2026 23:40
…rary

On macOS, system daemons (cfprefsd, lsd) automatically create
$HOME/Library/ for any process whose HOME they observe. Since the
build env sets HOME=tmpDir, these daemons can recreate Library/
inside a target's temporary directory during or just after cleanup,
causing os.RemoveAll to fail with ENOTEMPTY.

Handle this with a platform-specific cleanTmpDir that detects the
Library/ directory on ENOTEMPTY and retries removal with bounded
backoff. Non-Darwin platforms get a zero-overhead passthrough.
@sean- sean- force-pushed the fix-macos-tmpdir-cleanup branch from f507195 to a0464d7 Compare April 1, 2026 23:47
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