Skip to content

Apply NuGet.Client close-on-exec fix - #8490

Merged
agocke merged 1 commit into
dotnet:mainfrom
agocke:dev-agocke-closeOnExec
Aug 20, 2026
Merged

agocke merged 1 commit into
dotnet:mainfrom
agocke:dev-agocke-closeOnExec

Conversation

@agocke

@agocke agocke commented Aug 20, 2026

Copy link
Copy Markdown
Member

Bug

Fixes:

Upstream PR: NuGet/NuGet.Client#7643

Description

Ports NuGet/NuGet.Client#7643 onto the current VMR NuGet.Client snapshot. Extracted files are created with close-on-exec on Linux, macOS, and FreeBSD.

The NuGet source manifest is intentionally unchanged because the upstream PR branch diverged from and is 433 commits behind the current VMR snapshot.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

No tests or documentation changes are needed for this direct port. The affected NuGet.Packaging project builds with zero warnings and errors, and NuGet.sln passes the whitespace verification.

Port NuGet/NuGet.Client#7643 to the current VMR snapshot without regressing the NuGet source-manifest revision.

Co-authored-by: Copilot <[email protected]>
Copilot AI lite review requested due to automatic review settings August 20, 2026 18:07
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team August 20, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports an upstream NuGet.Client fix into the dotnet/dotnet VMR to ensure extracted files are created with close-on-exec semantics on Unix-like platforms, reducing unintended file descriptor inheritance across exec.

Changes:

  • Switches the Unix P/Invoke file creation path from creat to open with O_CLOEXEC and OS-specific flag values.
  • Adds OS-specific flag selection for Linux, macOS, and FreeBSD.
  • Updates the related CA1303 suppression string to match the new error message text.
Show a summary per file
File Description
src/nuget-client/src/NuGet.Core/NuGet.Packaging/NuGetExtractionFileIO.cs Uses open with O_CLOEXEC (and OS-specific flag constants) to create extracted files with close-on-exec behavior.
src/nuget-client/src/NuGet.Core/NuGet.Packaging/GlobalSuppressions.cs Updates suppression text to match the adjusted exception message in NuGetExtractionFileIO.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (1)

src/nuget-client/src/NuGet.Core/NuGet.Packaging/NuGetExtractionFileIO.cs:90

  • PosixOpen uses O_WRONLY (via OpenWriteOnly), but the returned FileStream is constructed with FileAccess.ReadWrite. This makes the stream report CanRead == true even though reads will fail with EBADF, and it diverges from the actual underlying descriptor access mode.

Either open with O_RDWR or (simpler since this is only used for writing during extraction) construct the FileStream as write-only to match the flags used.

            var sfh = new SafeFileHandle((IntPtr)fd, ownsHandle: true);

            try
            {
                return new FileStream(sfh, FileAccess.ReadWrite);
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

@agocke
agocke merged commit 07a8448 into dotnet:main Aug 20, 2026
11 checks passed
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.

3 participants