Skip to content

rtk dotnet build/test/restore hangs forever when a long-lived child daemon (NuGet auth plugin / MSBuild node) inherits the captured stdout/stderr pipe #2320

Open

Description

@alexdrl

rtk dotnet build/test/restore hangs forever when a long-lived child daemon inherits the captured stdout/stderr pipe (e.g. NuGet auth plugin / MSBuild node reuse)

Note: This issue was investigated and written with the help of Claude Code (it inspected rtk's source and a live hung process). I don't have any expertise on this repo or Rust — I just hit the bug and am trying to help with a useful report. Please take the suggested fixes as pointers, not prescriptions.

Summary

rtk dotnet build <proj> never returns on a project that restores from an authenticated NuGet feed (e.g. Azure DevOps Artifacts), even though the build itself completes successfully in seconds. Plain dotnet build and rtk run "dotnet build ..." both work fine.

The hang is after the build finishes. Root cause: the dotnet wrapper captures output via Command::output() (exec_capture), which reads the child's stdout/stderr pipes until EOF. A long-lived grandchild daemon — the NuGet Azure Artifacts Credential Provider running in persistent -Plugin mode — inherits the write end of the stderr pipe and outlives the build. The build's direct dotnet process exits (becomes a zombie), but the pipe never reaches EOF because the daemon still holds it open, so Command::output() blocks forever in read().

This is a general bug: Command::output() blocks on pipe EOF, not on the direct child exiting. Any descendant that inherits the captured fds and lingers (NuGet credential provider plugin, MSBuild node reuse worker nodes, the MSBuild build server, VBCSCompiler/Razor build server) can trigger it.

Environment

  • rtk 0.42.3 (also present in 0.42.2 source)
  • .NET SDK 10.0.300
  • Linux (Debian 13, kernel 6.12)
  • Project restores from a private Azure DevOps Artifacts feed → triggers CredentialProvider.Microsoft.dll -Plugin

Reproduction

# Hangs forever (build finishes in ~35s, rtk never returns):
rtk dotnet build path/to/SomeProject.csproj

# Works (passthrough, inherits the terminal, no captured pipe):
rtk run "dotnet build path/to/SomeProject.csproj"

# Works (TTY, no pipe):
dotnet build path/to/SomeProject.csproj

The trigger is having an authenticated NuGet feed configured (so dotnet restore launches the credential-provider plugin). A non-trivial project that restores from such a feed is enough.

Evidence (live inspection of the hung process)

1. The build finishes — the binlog stops growing — but rtk keeps running:

[10s] rtk_up=yes dotnet=19 binlog size=913365
[20s] rtk_up=yes dotnet=19 binlog size=1159802
[30s] rtk_up=yes dotnet=19 binlog size=1382604
[40s] rtk_up=yes dotnet=19 binlog size=2104543   <- build done, binlog finalized
[50s] rtk_up=yes dotnet=19 binlog size=2104543
 ...  rtk still running, size frozen, indefinitely

2. rtk's main thread is blocked reading the stderr pipe:

$ ps -L -o tid,stat,wchan,comm -p <rtk>
   TID STAT WCHAN       COMMAND
100308 S    pipe_read   rtk

$ ls -l /proc/<rtk>/fd | grep pipe
4 -> pipe:[544004]
6 -> pipe:[544005]

3. The build's direct child has already exited (zombie), yet the stderr pipe write-end is held open by the NuGet credential-provider daemon:

# rtk's direct child = zombie -> build process already exited
pid=100311 ppid=<rtk> stat=Z  [dotnet] <defunct>

# Who still holds rtk's stderr pipe (inode 544005) open?
pid 100596 (dotnet):
    fd 2 -> pipe:[544005]
    fd 7 -> pipe:[544005]

$ ps -o args= -p 100596
/usr/share/dotnet/dotnet \
  /home/<user>/.nuget/plugins/netcore/CredentialProvider.Microsoft/CredentialProvider.Microsoft.dll -Plugin

The credential provider is reparented away from rtk and lives on as a persistent plugin daemon, keeping the stderr pipe open → EOF never arrives → Command::output() blocks in read() forever.

Root cause in code

src/cmds/dotnet/dotnet_cmd.rs — run_build/run_test/run_restore → run_dotnet_with_binlog → exec_capture(&mut cmd).

src/core/stream.rs:

pub fn exec_capture(cmd: &mut Command) -> Result<CaptureResult> {
    cmd.stdin(Stdio::null());
    let output = cmd.output().context("Failed to execute command")?; // <-- reads stdout+stderr to EOF
    ...
}

Command::output() waits for EOF on both pipes, which only happens once every process holding a write end closes it — not when the direct child exits. A lingering grandchild daemon that inherited the fd makes EOF unreachable.

Note run_streaming's non-passthrough paths have the same structural issue: they join() the stdout/stderr reader threads (which loop until EOF) and only then child.wait(). Passthrough mode is safe precisely because it uses Stdio::inherit() and never creates a captured pipe.

Why the workarounds work

  • dotnet build (no rtk): stdout is a TTY; no pipe to keep open. The daemon shares the TTY; the shell returns when the foreground process exits.
  • rtk run "dotnet build ...": Passthrough = Stdio::inherit() (run_streaming, src/core/stream.rs), so there is no captured pipe to block on.

Suggested fixes

The capture must key off the direct child exiting, not pipe EOF. Some options:

  1. Stop waiting on EOF once the direct child has exited. Read stdout/stderr on threads, but after child.wait() returns, do a final non-blocking drain of whatever is buffered and return — don't join() reader threads that may block forever. (A short grace period after child exit is enough to flush legitimate trailing output.)
  2. Isolate descendants from the captured fds. Spawn the child in its own process group / session and, after it exits, stop reading. Or ensure the captured pipes are not inherited by grandchildren (where feasible).
  3. Combination: child-exit-driven completion + bounded post-exit drain. This is robust against all lingering daemons (NuGet credential provider, MSBuild node reuse, build server, VBCSCompiler/Razor server), not just this one.

A targeted mitigation (passing -nodeReuse:false, DOTNET_CLI_USE_MSBUILD_SERVER=0, etc.) does not fix this case, because the daemon here is the NuGet credential-provider plugin, which is independent of MSBuild node reuse. The real fix is to not block on pipe EOF.

Activity

  1. pszymkowiak commented on Jun 8, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    rtk dotnet build/test/restore hangs forever because Command::output() blocks on pipe EOF when a long-lived grandchild process (NuGet credential provider daemon) inherits the captured stderr pipe — fix by keying completion on direct child exit, not pipe EOF.

    📁 Relevant files
    • src/cmds/dotnet/dotnet_cmd.rs
    • src/core/stream.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions