ramvasanth / thread-sanitizer

Automatically exported from code.google.com/p/thread-sanitizer
0 stars 0 forks source link

Deadlock on close() after fork() #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a multi-threaded program built with TSAN that occasionally forks. The 
child process, before calling exec(), closes all of the open file descriptors. 
We're careful to not allocate any memory or take locks in the forked process, 
but with TSAN, we occasionally hit a deadlock like:

#0  0x00007f862243a319 in syscall () from /lib64/libc.so.6
#1  0x00007f862a650ae5 in __tsan::Mutex::Lock() ()
#2  0x00007f862a65e9ea in __tsan::SyncTab::GetAndRemove(__tsan::ThreadState*, 
unsigned long, unsigned long) ()
#3  0x00007f862a62b106 in __tsan::unref(__tsan::ThreadState*, unsigned long, 
__tsan::FdSync*) ()
#4  0x00007f862a62b060 in __tsan::FdClose(__tsan::ThreadState*, unsigned long, 
int) ()
#5  0x00007f862a636118 in close ()
#6  0x00007f8624038fdd in xxx::(anonymous 
namespace)::CloseNonStandardFDs(__dirstream*) () from xxx
#7  0x00007f86240388f2 in xxx::Subprocess::Start() () from xxx

It seems like TSAN should somehow avoid taking locks in a child process after a 
fork().

Original issue reported on code.google.com by tlip...@gmail.com on 22 Jul 2014 at 3:45

GoogleCodeExporter commented 9 years ago
What version of tsan do you use? I think this must be fixed on tip.

Original comment by dvyu...@google.com on 22 Jul 2014 at 7:41

GoogleCodeExporter commented 9 years ago
This was Clang/LLVM 3.3. I looked at the changes in git but didn't see any 
commits which would have fixed this -- of course I may have missed something.

Original comment by tlip...@gmail.com on 22 Jul 2014 at 7:59

GoogleCodeExporter commented 9 years ago
What git are you looking at? LLVM uses svn.

Original comment by dvyu...@google.com on 22 Jul 2014 at 8:04

GoogleCodeExporter commented 9 years ago
http://llvm.org/git/compiler-rt.git -- though I realized I was looking at the 
wrong branch. Now I see your commit "tsan: do not deadlock on fork" (r199993) 
which ought to fix this. Looks like this isn't in any release yet, but I'll see 
if I can get it into a local toolchain at some point. Thanks!

Original comment by tlip...@gmail.com on 22 Jul 2014 at 8:07

GoogleCodeExporter commented 9 years ago
Here are some related changes:
http://llvm.org/viewvc/llvm-project?view=revision&revision=199993
http://llvm.org/viewvc/llvm-project?view=revision&revision=204809
http://llvm.org/viewvc/llvm-project?view=revision&revision=206980

Original comment by dvyu...@google.com on 22 Jul 2014 at 8:09

GoogleCodeExporter commented 9 years ago
Here are instructions for building tip clang:
https://code.google.com/p/address-sanitizer/wiki/HowToBuild

Original comment by dvyu...@google.com on 22 Jul 2014 at 8:11

GoogleCodeExporter commented 9 years ago
Closing this for now. Please reopen if it still happens on tip.

Original comment by dvyu...@google.com on 22 Jul 2014 at 8:12

GoogleCodeExporter commented 9 years ago
Adding Project:ThreadSanitizer as part of GitHub migration.

Original comment by gli...@google.com on 30 Jul 2015 at 9:21