mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
MonitorFdHup
: replace pthread_cancel
trick with a notification pipe
On https://github.com/NixOS/nix/issues/8946, we faced a surprising behaviour wrt. exception when using pthread_cancel. In a nutshell when a thread is inside a catch block and it's getting pthread_cancel by another one, then the original exception is bubbled up and crashes the process. We now poll on the notification pipe from the thread and exit when the main thread closes its end. This solution does not exhibit surprising behaviour wrt. exceptions. Co-authored-by: Mic92 <joerg@thalheim.io> Fixes https://github.com/NixOS/nix/issues/8946 See also Lix https://gerrit.lix.systems/c/lix/+/1605 which is very similar by coincidence. Pulled a comment from that.
This commit is contained in:
parent
cb95791198
commit
1c636284a3
2 changed files with 49 additions and 11 deletions
18
src/libutil-tests/monitorfdhup.cc
Normal file
18
src/libutil-tests/monitorfdhup.cc
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "util.hh"
|
||||
#include "monitor-fd.hh"
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nix {
|
||||
TEST(MonitorFdHup, shouldNotBlock)
|
||||
{
|
||||
Pipe p;
|
||||
p.create();
|
||||
{
|
||||
// when monitor gets destroyed it should cancel the
|
||||
// background thread and do not block
|
||||
MonitorFdHup monitor(p.readSide.get());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue