Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367502 - WebSocket connections should be closed when application context is stopped
Summary: WebSocket connections should be closed when application context is stopped
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: websocket (show other bugs)
Version: 7.6.0.RC0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 7.5.x   Edit
Assignee: Simone Bordet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-23 11:20 EST by Simone Bordet CLA
Modified: 2011-12-23 18:38 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simone Bordet CLA 2011-12-23 11:20:34 EST
When an application context is stopped (or stopped and restarted which is what happens on redeploy), WebSocket connections should be closed, and currently they are not.

The reason is that WebSocket connections are stateful (differently from Http connections that are stateless), so they have a context that cannot be reused across restarts.
Comment 1 Simone Bordet CLA 2011-12-23 18:38:42 EST
Fixed by making WebSocketFactory extends AbstractLifeCycle, and tracking WebSocketServletConnections.
When WebSocketFactory is stopped, connections are closed with code 1001 (close_shutdown).

The same has been made for WebSocketClientFactory: connections are now tracked and when it's stopped, connections are closed with code 1001.

In both cases, connections are tracked using a ConcurrentLinkedQueue.

Addition to the queue is done before invoking application callbacks such as onOpen(), and only if the factory is running.
Removal from the queue piggybacks on the Connection.onClose() callback, that is invoked by the I/O layer when a connection is closed.
When the factory is being stopped, no additions are possible, and only removals or iteration over connections may be concurrent. Closing a connection that is already closed is a no-op, so we're safe.