jakartaee / websocket

Jakarta WebSocket
https://projects.eclipse.org/projects/ee4j.websocket
Other
61 stars 43 forks source link

Need an abort() method and a async close() method for Websockets #216

Open glassfishrobot opened 11 years ago

glassfishrobot commented 11 years ago

In Websocket 1.0, the javax.websocket.Session class provides methods #getBasicRemote() and #getAsyncRemote() which returns different RemoteEndpoints for either sending message synchronously (RemoteEndpoint.Basic) or asynchronously (RemoteEndpoint.Async).

However, to close a Websocket session (send the closing handshake) the only method is javax.websocket.Session#close(...). As it is a synchronous method it may block if there is no window on the underlying TCP connection to send the closing handshake. This can be a problem for implementations that only use Async I/O for sending Websocket message which are then forced to use Sync/Blocking I/O for sending the closing handshake. (For example, in .Net, there is System.Net.WebSockets.WebSocket#CloseOutputAsync() method that async closes the WebSocket session.)

Also, javax.websocket.Session does not have a method to abort a WebSocket connection immediately. This might be needed for an application that needs to disconnect a Client e.g. as DoS prevention (for example, when a connected client reads data from the underlying TCP connection very slowly so that the App needs to buffer more and more messages for that client, the application may want to immediately abort the WebSocket connection). Currently this is not possible - the App would need to wait to be able to send the closing handshake. (For example, in .Net there is System.Net.WebSockets.WebSocket#Abort() method that immediately aborts the WebSocket connection and cancels all pending I/O operations.)

Please see the thread on [1] for a discussion on Tomcat's Users list about these issues.

[1] http://markmail.org/message/z2pxdxeto656byu3

Affected Versions

[1.0]

glassfishrobot commented 6 years ago
glassfishrobot commented 11 years ago

@glassfishrobot Commented Reported by preisser144

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA WEBSOCKET_SPEC-216