Skip to content

Commit

Permalink
Prevent a deadlock when user namespace setup fails
Browse files Browse the repository at this point in the history
Observed on Centos 7 when user namespaces are disabled:
DerivationGoal::startBuilder() throws an exception, ~DerivationGoal()
waits for the child process to exit, but the child process hangs
forever in drainFD(userNamespaceSync.readSide.get()) in
DerivationGoal::runChild(). Not sure why the SIGKILL doesn't get
through.

Issue #4092.
  • Loading branch information
edolstra committed Oct 6, 2020
1 parent ad143c5 commit d761485
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,12 @@ void DerivationGoal::startBuilder()

userNamespaceSync.readSide = -1;

/* Close the write side to prevent runChild() from hanging
reading from this. */
Finally cleanup([&]() {
userNamespaceSync.writeSide = -1;
});

pid_t tmp;
if (!string2Int<pid_t>(readLine(builderOut.readSide.get()), tmp)) abort();
pid = tmp;
Expand All @@ -2712,7 +2718,6 @@ void DerivationGoal::startBuilder()

/* Signal the builder that we've updated its user namespace. */
writeFull(userNamespaceSync.writeSide.get(), "1");
userNamespaceSync.writeSide = -1;

} else
#endif
Expand Down

0 comments on commit d761485

Please sign in to comment.