Search code examples
jettyatmosphere

Atmosphere.js 501 Websocket protocol not supported


On Atmosphere 2.2.0 running on Jetty with a Python websocket-client-0.20.0 client, sometimes, although rarely, we get a situation where our logs fill up with the following:

12:18:01.105 WARN  org.atmosphere.websocket.WebSocket: Unable to write 501 Websocket protocol not supported
12:18:01.106 WARN  o.a.w.protocol.SimpleHttpProtocol: Status code higher or equal than 400. Unable to deliver the websocket messages to installed component. Status 501 Message Websocket protocol not supported

This spamming happens really fast, at about 5ms intervals, and if this occurs in production there is no other way than to take the system down. So we really need to avoid this.

It may be an issue in our client, but what I'm wondering is if there is a way to recognize these kinds of errors at the server back-end and to just close the connection, if we can't come up with a fix to the root cause?

... edit, some six months later: This issue seems to arise from an earlier Jetty exception:

11:05:54.363 ERROR o.a.container.Jetty9WebSocketHandler: {} org.eclipse.jetty.websocket.api.WebSocketTimeoutException: Timeout on Read at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onReadTimeout(AbstractWebSocketConnection.java:521) [devi ce-interaction-service-1.0.jar:na] at org.eclipse.jetty.io.AbstractConnection.onFillInterestedFailed(AbstractConnection.java:258) [device-interaction-service-1.0 .jar:na] at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillInterestedFailed(AbstractWebSocketConnection.java:4 97) [device-interaction-service-1.0.jar:na] at org.eclipse.jetty.io.AbstractConnection$ReadCallback$1.run(AbstractConnection.java:420) [device-interaction-service-1.0.jar :na] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) [device-interaction-service-1.0.jar:na] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) [device-interaction-service-1.0.jar:na] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_51] 11:05:54.365 DEBUG o.a.w.DefaultWebSocketProcessor: Unable to properly complete 2d48f7ce-6150-42c2-b815-93acf94bdb93 11:05:55.156 WARN org.atmosphere.websocket.WebSocket: Unable to write 501 Websocket protocol not supported 11:05:55.157 WARN o.a.w.protocol.SimpleHttpProtocol: Status code higher or equal than 400. Unable to deliver the websocket messages to installed component. Status 501 Message Websocket protocol not supported 11:05:55.201 WARN org.atmosphere.websocket.WebSocket: Unable to write 501 Websocket protocol not supported 11:05:55.202 WARN o.a.w.protocol.SimpleHttpProtocol: Status code higher or equal than 400. Unable to deliver the websocket messages to installed component. Status 501 Message Websocket protocol not supported 11:05:55.203 WARN org.atmosphere.websocket.WebSocket: Unable to write 501 Websocket protocol not supported ...

It also does seem to me that the connection is left hanging, and no @Disconnect method gets called on my @ManagedService.

I wonder how to intercept this and to just shut down the connection, forcing the client to reconnect.


Solution

  • Write your own WebSocketProtocol or extends the SimpleHttpProtocol#onError https://github.com/Atmosphere/atmosphere/wiki/Writing-WebSocket-Sub-Protocol