Skip to content

Use close-on-exec for extracted files - #7643

Merged
zivkan merged 7 commits into
NuGet:devfrom
agocke:agocke/add-cloexec-to-extraction-files
Aug 28, 2026
Merged

zivkan merged 7 commits into
NuGet:devfrom
agocke:agocke/add-cloexec-to-extraction-files

Conversation

@agocke

@agocke agocke commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes dotnet/dotnet#8079

This changes nuget to use the managed File.Create API instead of P/Invoke on Unix systems.

The fundamental problem here is that NuGet opens potentially executable files on Unix without passing the O_CLOEXEC flag. This creates a problem when a new process is created, either in another thread or the same thread, while the file descriptor is opened. The new process will inherit the FD through fork/exec. That means that attempting to execute the target file will fail because there is an open FD to the executable file and executing files with open handles is prohibited by the Linux kernel (ETXTBSY).

The simpler framing of the issue is basically that NuGet is a library and opens FDs without O_CLOEXEC. The runtime maintains a contract that all FDs are opened with that flag to avoid problems like the above. All libraries that can't control their entire process environment should also set that flag to ensure there are no problems with FD inheritance.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 518424ce-5e6d-4b17-893b-31452457209c
@agocke
agocke requested a review from a team as a code owner August 20, 2026 17:44
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Aug 20, 2026
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 518424ce-5e6d-4b17-893b-31452457209c
akoeplinger
akoeplinger previously approved these changes Aug 21, 2026
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 023830e7-e6fb-49cf-a154-7e41f833fb08
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 023830e7-e6fb-49cf-a154-7e41f833fb08
akoeplinger
akoeplinger previously approved these changes Aug 24, 2026
@nkolev92

Copy link
Copy Markdown
Member

Can we get some details in the PR description about the exact fix.
The title suggests a simple changes, but the changeset is sizable.

I'd also love to see the details about the issue to be in the NuGet repo.
That way we can document the scenario properly in release notes, since our automation won't query dotnet/dotnet issue.

@agocke

agocke commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@nkolev92 The fix is simple -- just use file.create instead of P/Invoke. All the other added code is tests. What else would you like to know?

@nkolev92

Copy link
Copy Markdown
Member

I appreciate the update in the description that part is helpful.

I think generally just more details about the intent and a more self-contained description, since the linked issue is talking about something completely different until the analysis further down. That'd make it easier to review.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 023830e7-e6fb-49cf-a154-7e41f833fb08
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 023830e7-e6fb-49cf-a154-7e41f833fb08
@mmitche

mmitche commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

@zivkan I think we need a backport of this fix to 10.0.1xx. This is killing many .NET 10 builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Operational Issue]: crossgen2 fails to start with Text file busy on Azure Linux cross-build legs

6 participants