-
Notifications
You must be signed in to change notification settings - Fork 353
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
Infinite loop due to thread safety of MpscUnboundedArrayQueue.poll #947
Comments
@xiazuojie I just noticed that you report that issue for 1.0.0-RC6, can you please check that this one is still an issue for 1.0.2 and 1.1.0-SNAPSHOT? At least 1.1.0 should not have this problem anymore |
it's still an issue in the latest master branch by checking the code. I cannot reproduce the issue reliably due to the complexity of multi-thread problem. |
I mean we still use a single consumer queue, but in the latest implementation, it should not be possible to run in that case when you dispose an UnboundedProcessor and poll elements at the same time which is the successor to MpScUnboundedQueue. |
Let me give it a check. I'll report back later |
Although the mentioned tests reproduce the issue, it does not represent how we use MpscQueue inside rsocket. Indeed, we had this issue of racing |
@xiazuojie do you have any updates on whether that issue reproduces with rsocket 1.1.0? |
@xiazuojie should be fixed in 1.0.4! Let me know if it works for you as well |
As its name (Multi Producer Single Consumer) indicates, MpscUnboundedArrayQueue is not thread-safe when polling. If multiple threads are polling from it, those threads may end up in infinite loop here:
UnboundedProcessor is internally using MpscUnboundedArrayQueue. When a connection needs to be terminated (due to no keep-alive acks or other reasons), more than 1 threads will try to poll from its MpscUnboundedArrayQueue.
As shown below,
Expected Behavior
Thread-safe. No infinite loop.
Actual Behavior
Threads sometimes end up in infinite loop when terminating a connection. It has happened 3 times in production for me.
Steps to Reproduce
Demo of infinite loop when multiple threads try to poll from MpscUnboundedArrayQueue.
Possible Solution
Replace MpscUnboundedArrayQueue with MPMC (Multi Producer Multi Consumer) queue.
Your Environment
netty
, ...):javar -version
) or Node version (node --version
)): Java(TM) SE Runtime Environment (build 1.8.0_101-b13)uname -a
):Darwin MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64The text was updated successfully, but these errors were encountered: