Open gavin-scott opened 9 years ago
Ahh nice, so we must have a thread-unsafe C API here? I could not get this to fail at all on OS X, so perhaps it's a thread unsafety issue in the Linux implementation of getgrnam.
Simple fix would be to lock known-unsafe kernel APIs. Any concerns?
I think using the thread-safe variant getgrnam_r
would make more sense. AFAICT getgrnam
happens to be thread-safe on Mac OS X but not on e.g. linux.
@gavin-scott so I guess we'd want to try getgrnam_r
and failover to getgrnam
, possibly with synchronization? We need to maintain a lowest common denominator too.
Why would you fall back? I think getgrnam_r
should be supported everywhere. Do you mean if getgrnam_r
fails for some reason? I would think raising an exception would be ok at this point, but honestly I don't know what the general pattern for handling low-level C library failures is in this code.
Well if we can count on getgrnam_r working everywhere, then I agree there's no reason not to use it for getgrnam.
Generally C library errors should just be propagated out. C binding problems we try to hide and fallback on alternatives as much as we can.
AFAIK getgrnam_r
is part of POSIX and should be available everywhere. I'm having trouble finding a good solid reference for that, but it is listed here: http://www.unix.com/man-page/posix/3p/getgrnam/
This was addressed recently in JRuby by locking around all those function calls. The same would probably be appropriate here.
Also, this affects many other "etc" functions. They probably all need thread-safety treatment.
We'd welcome help. It might just be adding "synchronized" to the LibC bindings of these methods, or renaming them to the new thread-safe versions @gavin-scott mentioned.
The JVM crashes on threaded use of Etc::getgrnam This happens on all versions of java 1.7 I tested with, e.g. the latest Oracle java 1.7 update 75. Tested with both jruby 1.7.8 and 1.7.19 on CentOS 6.6 A sample test program that will demonstrate the problem is:
This always crashes for me, usually it takes less than 200 iterations or so: