-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
WebSocket text event execute in same thread as running binary event and destroy Threadlocal #5368
Comments
Your description has not been a supported feature before or now. How it works ... Other notes about your question/comment ... |
Yes, this is the feature that I expected and that Jetty not implement. Every event should be processed in its own thread from a pool.
Sounds you misunderstand me. I does not switch the thread. We save the scope of the current event in ThreadLocal variables. The problem is that Jetty handle a second event in the same thread inside the message.read() call. This override the ThreadLocal variables of the first event. Many APIs from Java use ThreadLocal for states and communication. For example the ContextClassLoader. Your implementation break all this java API. |
This is standard, and has been this way since Jetty 9.1.0 (when javax.websocket was first supported) The next
The inputstream.read() is on your thread, not Jetty.
Most of these have been systematically removed over the years as they are hostile to async development efforts. The This means that the Endpoint is called in a way to guarantee no two container threads are calling the endpoint at the same time. |
From your link:
This is the problem. Jetty interleave one onMessage() with another onMessage(). The stacktrace look like:
|
What's There's no method called "read()" in the javax.websocket APIs. Note that you are using If the entire message fits in a handful of websocket frames (again, you are abusing So you can get ...
From the point of view of both |
Also, this part of the spec refers to use of the You basically have this ...
Notice that both of the Whole streaming API choices don't deliver on WHOLE message received, but only on the start of a new TEXT or BINARY websocket frame. (a frame that triggered this call to new Thread(new Runnable() {
public void run(){
registeredEndpointMessageHandler.onMessage(inputStream);
} } ).start(); ... for each new message, imagine what happens if many new messages arrive close to each other (even in the same read network buffer)? |
The changes made in #4486 seem relevant to this issue. Since
I think this is the core of the issue. I think the call to But I don't understand how this would override your ThreadLocal variables of the first |
@Horcrux7 can you give a full stacktrace of where the second |
Here is a stacktrace where:
Message count and size: We use a large count of small messages (some KB) and a few large messages (<100MB) for file uploads. It is a mix of small and large messages. |
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
…Stream Issue #5368 - ensure onMessage exits before next frame is read
This is fixed by PR #5377 and will be in the 9.4.33 release. |
Reopening to verify fix in Jetty 10 as most of changes couldn't be merged. |
This issue has been automatically marked as stale because it has been a |
This is not an issue in 10.0.x as the demand mechanism is used to control when frames are requested for the |
Jetty version: 9.4.31
Java version: 11.09 but also with 8.0.x
OS type/version: any
Description
If the WebSocket MessageHandler is registered as:
then is can occur that inside
message.read()
in the same thread a text message will be processed. In this case two MessageHandler are share the same thread local variables. On security reasons our MessageHandlers destroy all ThreadLocal variables on finish for the current thread. The result for the first binary MessageHandler is that there is no current user scope after somemessage.read()
.This has work in version 9.4.20. It is a regression in a micro version or fatal behavior change. We was not able to find a documentation that forbids Threadlocal with WebSocket events handling. We expected that an intermediate event will process in another thread or later.
A workaround is to switch to
MessageHandler.Whole<byte[]>
. Then there is nomessage.read()
call anymore. But it sounds fewer effective.The text was updated successfully, but these errors were encountered: