-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
WebSocketWorker
does not handle Throwable
#1160
Comments
Hello @Marcono1234, Best regards, |
The issue is that the worker threads just die (without being replaced). So eventually once all worker threads have died the web socket server will be unable to process any subsequent connections since no worker thread is left for processing the messages. I think large HTTP server frameworks usually catch However, if you decide that the worker threads should not only log |
Yeah, I just tried and it can indeed bring down the entire server. The most common way would probably be AssertionError. Not sure how realistic it is to recover from other errors though. |
So we call onError in this case and shut down everything? |
If so, then when the callback returns successfully (without throwing an exception), it would be good if the worker thread would continue running, or would be replaced. Otherwise such a callback would not add much value since still eventually all worker threads would have died. It might also be good to verify whether a worker which has encountered a |
Ok I confirm, it's the same so no solution without forking ? |
Feel free to open a PR |
Describe the bug
The
WebSocketWorker
does not catch thrown (non-Exception
)Throwable
s; instead they cause the worker thread to die. Even though in general catchingThrowable
should be avoided it seems appropriate here, otherwise an adversary could exploit a vulnerability in the application, killing one worker thread after the other until no more workers are remaining, causing a denial of service.Even though
java.lang.Error
is described as:Some of the subclasses are thrown for non-serious problems, e.g.
StackOverflowError
could occur when malicious deeply nested data is deserialized.To Reproduce
Steps to reproduce the behavior:
onMessage(WebSocket, String)
method of the exampleChatServer
to throw ajava.lang.Error
(simulating an error in the application code)ExampleClient
multiple times❌ At some point all worker threads have died
Expected behavior
WebSocketWorker
should catchThrowable
and log it as fatal error, but it should not terminate due to it.Alternatively shut down the complete server so whoever started it will notice that an error occurred (and can restart the server).
Environment
Additional context
It appears in previous versions the following
catch
block forRuntimeException
s would have caused a complete server shutdown, see #207:Java-WebSocket/src/main/java/org/java_websocket/server/WebSocketServer.java
Lines 1082 to 1084 in 5f8d597
However, in current versions that
catch
block cannot be reached (except for bugs caused by this library) since the called methoddoDecode
catches and logs any thrownException
.The text was updated successfully, but these errors were encountered: