Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Add Warning: conflicting chdir during another chdir block #5649
Ok I think I know what's happening here.
In JRuby we do localize the current dir to a given JRuby instance, so that we can support more than one current dir per JVM process, but we do not localize it on a per-thread basis.
The error you're getting here is likely because there are two threads attempting to create, chdir, and remove a temporary dir, and there's a number of ways they could be stepping on each other. It manifests as an ENOENT probably because one of the tmp dirs is getting wiped out while in use. MRI does not manifest the same error because it's at least only running one thread at a time; they still could conflict (and potentially ENOENT) if there's a context switch from one thread to another, but it would be more rare.
I have two patches for this. The first just adds the warning, using a ReentrantLock to detect whether some other thread is doing the chdir, but otherwise proceeding without locking. The second version actually does attempt to wait for the lock, making chdir thread-safe.
With the first patch, I do see the warnings you expect, but also the errors you got. This may be the best we can do for this code, since it's rather problematic.
The second patch, as you'd expect, does not present the errors. There's a string of warnings as the threads get going, but then they execute the chdir blocks in serial.
I'm not sure which way to go with this for now. If we want to actually make stacked chdirs block, we probably should raise this as a feature change in MRI as well. If we don't, this code will warn but otherwise still usually error out.
@headius Thanks for the response and the detailed explanation. The above code-snippet results in ENOENT errors with MRI as well.
I started seeing intermittent ENOENT errors and started with debugging the block passed to
As part of the JRuby issue template, I tried running the code in MRI and noticed the warning