Skip to content

Commit

Permalink
Handle CONNECTED after CLOSED message is sent race condition
Browse files Browse the repository at this point in the history
This happens because connections are now closed when a test is complete, which means this can feasibly happen before the CONNECTED message is received from Ably
  • Loading branch information
mattheworiordan committed Oct 5, 2015
1 parent cdf49f4 commit 58cb004
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ably/realtime/client/incoming_message_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ def dispatch_protocol_message(*args)

when ACTION.Connect
when ACTION.Connected
connection.transition_state_machine :connected, reason: protocol_message.error, protocol_message: protocol_message unless connection.connected?
if connection.disconnected? || connection.closing? || connection.closed? || connection.failed?
logger.debug "Incoming CONNECTED ProtocolMessage discarded as connection has moved on and is in state: #{connection.state}"
elsif connection.connected?
logger.error "CONNECTED ProtocolMessage should not have been received when the connection is in the CONNECTED state"
else
connection.transition_state_machine :connected, reason: protocol_message.error, protocol_message: protocol_message
end

when ACTION.Disconnect, ACTION.Disconnected
connection.transition_state_machine :disconnected, reason: protocol_message.error unless connection.disconnected?
Expand Down

0 comments on commit 58cb004

Please sign in to comment.