Skip to content

Commit

Permalink
Don't wait for writing to the socket to finish before closing in the …
Browse files Browse the repository at this point in the history
…case of a close timeout.
  • Loading branch information
jcoglan committed Aug 1, 2017
1 parent db395df commit e222fa4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/faye/websocket/api.rb
Expand Up @@ -43,7 +43,7 @@ def initialize(options = {})

@driver.on(:open) { |e| open }
@driver.on(:message) { |e| receive_message(e.data) }
@driver.on(:close) { |e| begin_close(e.reason, e.code) }
@driver.on(:close) { |e| begin_close(e.reason, e.code, :wait_for_write => true) }

@driver.on(:error) do |error|
emit_error(error.message)
Expand Down Expand Up @@ -121,13 +121,17 @@ def emit_error(message)
dispatch_event(event)
end

def begin_close(reason, code)
def begin_close(reason, code, options = {})
return if @ready_state == CLOSED
@ready_state = CLOSING
@close_params = [reason, code]

if @stream
@stream.close_connection_after_writing
if options[:wait_for_write]
@stream.close_connection_after_writing
else
@stream.close_connection
end
else
finalize_close
end
Expand Down

0 comments on commit e222fa4

Please sign in to comment.