-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition in AsyncFileImpl writesOutstanding #2012
Comments
a couple of questions:
|
|
I think the issue is that writeOutstanding can be increased here: At the same time it is decreased here: If write is called from a different thread to the context thread. I tried using synchronized to fix initially but this resulted in a deadlock. Volatile can't be used as volatile adds aren't atomic. |
can you provide a reproducer ? |
Sure, will try and put one together :) |
Here's a reproducer that can run inside vertx-core FileSystemTest: https://gist.github.com/purplefox/6de14775d331395ceeb01168367715f4 It needs to be run with many iterations to reproduce (hence the @repeat) |
If you run the test enough times you will find it hangs eventually, this is because the close() method never completes. It doesn't complete because it is waiting for an invalid value of outstanding writes. |
makes sense thank! |
I pushed a branch with a fix, I used synchronized because that's the class synchronization pattern and also it was necessary to read the |
thanks for the report, the patch and the reproducer! |
If an AsyncFileImpl is written to from a thread different to the context that created then the long counter writesOutstanding can get into an invalid state. This is because the counter is updated from both the caller's thread and also on the context when a write is complete.
Fix is to use an AtomicLong for writesOutstanding:
https://gist.github.com/purplefox/723fa69a1330fb4f4f74d4a5dd5e6658
The text was updated successfully, but these errors were encountered: