Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fail the WebSocket connection on protocol error

This is correct according to the spec for invalid UTF-8 errors. The spec isn't clear for other errors (e.g. receiving a message which is too large), but failing the connection seems appropriate.

Specifically this means that we send the close code and then _close the tcp connection_. Previously there was a bug where the input stream would not be processed and therefore a close handshake ack would not be processed, leaving the connection open.

Also refactored this logic into handler
  • Loading branch information...
commit d6758b550e8bf3a9d930e04fad0f933526929021 1 parent ff63781
@mloughran mloughran authored
Showing with 10 additions and 4 deletions.
  1. +0 −4 lib/em-websocket/connection.rb
  2. +10 −0 lib/em-websocket/handler.rb
View
4 lib/em-websocket/connection.rb
@@ -76,10 +76,6 @@ def receive_data(data)
else
dispatch(data)
end
- rescue WSProtocolError => e
- debug [:error, e]
- trigger_on_error(e)
- close_websocket_private(e.code, e.message)
rescue => e
debug [:error, e]
View
10 lib/em-websocket/handler.rb
@@ -44,12 +44,22 @@ def initialize(connection, debug = false)
def receive_data(data)
@data << data
process_data
+ rescue WSProtocolError => e
+ fail_websocket(e)
end
def close_websocket(code, body)
# Implemented in subclass
end
+ # This corresponds to "Fail the WebSocket Connection" in the spec.
+ def fail_websocket(e)
+ debug [:error, e]
+ close_websocket(e.code, e.message)
+ @connection.close_connection_after_writing
+ @connection.trigger_on_error(e)
+ end
+
def unbind
@state = :closed
Please sign in to comment.
Something went wrong with that request. Please try again.