Skip to content

nsenter: fix FUSE deadlock from synchronous child waits#121

Open
benjamincburns wants to merge 2 commits into
nestybox:masterfrom
benjamincburns:fix/fuse-deadlock
Open

nsenter: fix FUSE deadlock from synchronous child waits#121
benjamincburns wants to merge 2 commits into
nestybox:masterfrom
benjamincburns:fix/fuse-deadlock

Conversation

@benjamincburns
Copy link
Copy Markdown

Fixes nestybox/sysbox#998. Builds on #119.

SendRequest() held the reaper RLock while synchronously waiting for nsenter child processes. If a child's exit was delayed by fuse_flush on inherited FUSE file descriptors, the RLock was held indefinitely, blocking both the reaper and new FUSE handlers.

This PR includes the TryLock fix from #119 and adds:

  • Move pipe read before PARENT wait (PARENT writes pid before exiting)
  • Replace synchronous Process.Wait() calls with background goroutines
  • Add reapProcessAsync for the INIT process to trigger a reaper sweep on exit
  • Regression tests for the changes from nsenter: use TryLock in reaper to prevent cascading FUSE deadlock #119 and the additional commit included in this PR.

Just for transparency, I am an experienced software engineer with some systems experience, but I'm not a go dev. I used AI tooling (Claude Code and Claude Opus 4.6) to find the underlying deadlock and author this fix. I'm mentioning that here in case this project has any policies against AI contributions. I don't want to subvert any such policy.

I have tested this fix on my own system. See notes in nestybox/sysbox#998 (comment).

Replace mu.Lock() with mu.TryLock() in the zombie reaper goroutine. Go's
sync.RWMutex implements writer-preference: a pending Lock() blocks all
subsequent RLock() callers. When the reaper's Lock() is pending while an
nsenter child holds RLock, all new FUSE Lookup handlers are blocked from
acquiring RLock to start their own nsenter processes. If the nsenter child's
operation triggers a FUSE request back to sysbox-fs, the FUSE handler cannot
proceed, creating a deadlock.

TryLock() does not register a pending writer, so FUSE handlers can still
acquire RLock. If TryLock fails, the reaper sleep a second to retry.

Fixes: nestybox/sysbox#1002
Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
@benjamincburns
Copy link
Copy Markdown
Author

cc @okhowang for visibility

SendRequest() held the reaper RLock while synchronously waiting for
nsenter child processes via Process.Wait(). If a child's exit was
delayed by the kernel's fuse_flush on inherited FUSE file descriptors,
the RLock was held indefinitely, preventing both the reaper and new
FUSE handlers from making progress.

Move the pipe read before the PARENT wait (the PARENT writes the pid
before exiting) and replace synchronous Process.Wait() calls with
background goroutines so the caller releases the RLock promptly.

Fixes: nestybox/sysbox#998
Signed-off-by: Ben Burns <803016+benjamincburns@users.noreply.github.com>
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.

Hangs when running simultaneous docker containers inside a sysbox container

2 participants