-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
onResume and onDisconnect are not fired with WebSocket connection. #814
Comments
OK just tested with 1.0.x and it worked as expected using the sample/chat. Now trying with 1.1.0-SNAPSHOT (master) |
Added to the samples/chat support for onDisconnect events Still unable to reproduce. Maybe you means AtmosphereResource.cancel() isn't calling onDisconnect? |
Ok some explanation. The AtmosphereResourceImpl.cancel() will close the underlying WebSocket, but this is not a public interface. With resume, the AtmosphereResourceImpl will be removed from Broadcaster, but the underlying connection will not be closed. The recommended way is to call AtmosphereResponse.closeStreamOrWriter(), which will close the underlying websocket. I think I need to work on a new API that close the websocket directly as well as the connection, independent of the transport. |
OK added both a test for onResume, onDisconnect and onClose here I cannot reproduce the issue with Jetty. |
Okay, I'll test it and get back to you |
About WebSocket and 'AtmosphereResponse.closeStreamOrWriter': Both closeStreamOrWriter doesn't affect the WebSocket connection -
|
With 1.1.0-SNAPSHOT, problem still occurs. Here's the scenario, and I'll check about added unit testss. Action
Situation 1 - error
Log:
No onResume and onDisconnect. Situation 2
Log:
There was onDisconnect in 2013-01-15 22:21:05,978 |
OK, first, like you noted, there is no API for closing a WebSocket connection. The resume will not close the connection. So I have filled #817. Now from your log I do see the onDisconnect called...but I may miss something, so let me try with your handler. |
OK, I installed your handler, ran the javascript, and got the following trace if I let the timer execute (so I don't close the client) INFO] Starting scanner at interval of 1 seconds.
13:26:43.726 [qtp2006761955-63] DEBUG o.a.w.DefaultWebSocketProcessor - Atmosphere detected WebSocket: org.atmosphere.container.version.Jetty8WebSocket
13:26:43.739 [qtp2006761955-63] DEBUG o.a.s.pubsub.TestAtmosphereHandler - onPreSuspend AtmosphereResourceEventImpl{isCancelled=false,
isResumedOnTimeout=false,
throwable=null,
message=null,
resource=AtmosphereResourceImpl{
hasCode1229554982,
action=Action{timeout=-1, type=CREATED},
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
asyncSupport=org.atmosphere.container.JettyAsyncSupportWithWebSocket@79c4a760,
serializer=null,
isInScope=true,
listeners=[org.atmosphere.interceptor.DefaultHeadersInterceptor$1@5dc8ce14, org.atmosphere.samples.pubsub.TestAtmosphereHandler$1@2a51b326]}}
13:26:43.740 [qtp2006761955-63] DEBUG o.a.s.pubsub.TestAtmosphereHandler - onSuspend AtmosphereResourceEventImpl{isCancelled=false,
isResumedOnTimeout=false,
throwable=null,
message=null,
resource=AtmosphereResourceImpl{
hasCode1229554982,
action=Action{timeout=-1, type=SUSPEND},
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
asyncSupport=org.atmosphere.container.JettyAsyncSupportWithWebSocket@79c4a760,
serializer=null,
isInScope=true,
listeners=[org.atmosphere.interceptor.DefaultHeadersInterceptor$1@5dc8ce14, org.atmosphere.samples.pubsub.TestAtmosphereHandler$1@2a51b326]}}
13:27:03.742 [Timer-0] DEBUG o.a.s.pubsub.TestAtmosphereHandler - Time to bid farewell
13:27:03.743 [Timer-0] DEBUG o.a.s.pubsub.TestAtmosphereHandler - onResume AtmosphereResourceEventImpl{isCancelled=false,
isResumedOnTimeout=false,
throwable=null,
message=null,
resource=AtmosphereResourceImpl{
hasCode1229554982,
action=Action{timeout=-1, type=RESUME},
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
asyncSupport=org.atmosphere.container.JettyAsyncSupportWithWebSocket@79c4a760,
serializer=null,
isInScope=true,
listeners=[org.atmosphere.interceptor.DefaultHeadersInterceptor$1@5dc8ce14, org.atmosphere.samples.pubsub.TestAtmosphereHandler$1@2a51b326]}}
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1273)
at org.atmosphere.samples.pubsub.TestAtmosphereHandler$1.onDisconnect(TestAtmosphereHandler.java:92)
at org.atmosphere.cpr.AtmosphereResourceImpl.onDisconnect(AtmosphereResourceImpl.java:697)
at org.atmosphere.cpr.AtmosphereResourceImpl.notifyListeners(AtmosphereResourceImpl.java:636)
at org.atmosphere.cpr.AtmosphereResourceImpl.resume(AtmosphereResourceImpl.java:311)
at org.atmosphere.samples.pubsub.TestAtmosphereHandler$1$1.run(TestAtmosphereHandler.java:70)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
13:27:03.744 [Timer-0] DEBUG o.a.s.pubsub.TestAtmosphereHandler - onDisconnect AtmosphereResourceEventImpl{isCancelled=true,
isResumedOnTimeout=false,
throwable=null,
message=null,
resource=AtmosphereResourceImpl{
hasCode1229554982,
action=Action{timeout=-1, type=RESUME},
broadcaster=org.atmosphere.cpr.DefaultBroadcaster,
asyncSupport=org.atmosphere.container.JettyAsyncSupportWithWebSocket@79c4a760,
serializer=null,
isInScope=true,
listeners=[org.atmosphere.interceptor.DefaultHeadersInterceptor$1@5dc8ce14, org.atmosphere.samples.pubsub.TestAtmosphereHandler$1@2a51b326]}} So both onDisconnect and onResume worked. |
OK confirm the issue with closing the browser and ondisconnect not called. Looking at it now. Thanks! |
Ah! The issue is the onClose is called, but not the onDisconnected. Fixing. |
Oh! The issue is you must extends WebSocketEventListener, not the AtmosphereResourceEventListener for getting the WebSocket's special events. Changing your AtmosphereHandler to use it make it work. Sorry I should have spotted the issue much before. I will mark the issue for documentation for 1.1 |
Thanks, I confirmed that it works with WebSocketEventListener. |
Full story: flowersinthesand/portal-java#21
onResume or onDisconnect are not fired with WebSocket connection. When
Simple question - Is it safe to close WebSocket connection using cancel method of AtmosphereResourceImpl? As far as I remember, resume method couldn't disconnect WebSocket so that the close event is not fired in the browser side, so I used cancel method instead. However I'm not sure.
The text was updated successfully, but these errors were encountered: