Skip to content

fix(patch): stop a workdir cleanup race from masking update errors#9798

Open
manzoorwanijk wants to merge 1 commit into
npm:latestfrom
manzoorwanijk:fix/patch-update-workdir-cleanup-race
Open

fix(patch): stop a workdir cleanup race from masking update errors#9798
manzoorwanijk wants to merge 1 commit into
npm:latestfrom
manzoorwanijk:fix/patch-update-workdir-cleanup-race

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Contributor

npm patch update builds a throwaway git repo in a temp dir to rebase the existing patch, then removes it. Two problems made that removal flaky:

Since git 2.48, maintenance.autoDetach defaults to true, so git commit detaches git maintenance run --auto and returns while that background process is still writing under .git/objects/pack. Removing the workdir then races it and fails with ENOTEMPTY.

Both cleanup sites removed the workdir with an unguarded await rm(...), so that failure replaced the command's real error, a EPATCHBASE rebase failure surfaced as ENOTEMPTY, and on the success path a cleanup failure would have failed an otherwise-complete update.

The throwaway repo's git invocations now pass -c gc.auto=0 -c maintenance.auto=false so git never spawns background maintenance, and both cleanup sites go through a helper that retries the removal and never throws.

References

Reported in #9793 (comment) as an unrelated CI failure.

@manzoorwanijk
manzoorwanijk marked this pull request as ready for review July 24, 2026 03:34
@manzoorwanijk
manzoorwanijk requested review from a team as code owners July 24, 2026 03:34
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