Skip to content

Commit

Permalink
Merge pull request #11665 from roberth/fix-Interrupted-falling-out-of…
Browse files Browse the repository at this point in the history
…-thread

Fix `Interrupted` falling out of thread crash
  • Loading branch information
roberth authored Oct 16, 2024
2 parents facc502 + ed184f0 commit f51974d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/libstore/unix/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <iostream>

#include "strings.hh"
#include "signals.hh"

namespace nix {

Expand Down Expand Up @@ -1579,6 +1580,8 @@ void LocalDerivationGoal::startDaemon()
FdSink(remote.get()),
NotTrusted, daemon::Recursive);
debug("terminated daemon connection");
} catch (const Interrupted &) {
debug("interrupted daemon connection");
} catch (SystemError &) {
ignoreExceptionExceptInterrupt();
}
Expand Down
7 changes: 7 additions & 0 deletions src/libstore/unix/build/local-derivation-goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,15 @@ struct LocalDerivationGoal : public DerivationGoal
*/
void writeStructuredAttrs();

/**
* Start an in-process nix daemon thread for recursive-nix.
*/
void startDaemon();

/**
* Stop the in-process nix daemon thread.
* @see startDaemon
*/
void stopDaemon();

/**
Expand Down
11 changes: 8 additions & 3 deletions src/libutil/thread-pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ void ThreadPool::doWork(bool mainThread)
propagate it. */
try {
std::rethrow_exception(exc);
} catch (const Interrupted &) {
// The interrupted state may be picked up by multiple
// workers, which is expected, so we should ignore
// it silently and let the first one bubble up,
// rethrown via the original state->exception.
} catch (const ThreadPoolShutDown &) {
// Similarly expected.
} catch (std::exception & e) {
if (!dynamic_cast<ThreadPoolShutDown*>(&e))
ignoreExceptionExceptInterrupt();
} catch (...) {
ignoreExceptionExceptInterrupt();
}
}
}
Expand Down

0 comments on commit f51974d

Please sign in to comment.