Skip to content

Commit

Permalink
Use Client#close rather than Client#cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Nov 29, 2018
1 parent 1666fee commit ca32197
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/message_bus/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def synchronize
end

# Closes the client connection
def cancel
def close
if cleanup_timer
# concurrency may nil cleanup timer
cleanup_timer.cancel rescue nil
Expand Down
4 changes: 2 additions & 2 deletions lib/message_bus/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def add_client(client)
synchronize do
existing = @clients[client.client_id]
if existing && existing.seq > client.seq
client.cancel
client.close
else
if existing
remove_client(existing)
existing.cancel
existing.close
end

@clients[client.client_id] = client
Expand Down
4 changes: 2 additions & 2 deletions lib/message_bus/rack/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def call(env)
backlog = client.backlog

if backlog.length > 0 && !allow_chunked
client.cancel
client.close
@bus.logger.debug "Delivering backlog #{backlog} to client #{client_id} for user #{user_id}"
[200, headers, [self.class.backlog_to_json(backlog)]]
elsif long_polling && env['rack.hijack'] && @bus.rack_hijack_enabled?
Expand Down Expand Up @@ -196,7 +196,7 @@ def add_client_with_timeout(client)

client.cleanup_timer = @bus.timer.queue(@bus.long_polling_interval.to_f / 1000) {
begin
client.cancel
client.close
@connection_manager.remove_client(client)
rescue
@bus.logger.warn "Failed to clean up client properly: #{$!} #{$!.backtrace}"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/message_bus/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse_chunk(data)
chunk2.first["data"].must_equal "a|\r\n|\r\n|b"

@client << MessageBus::Message.new(3, 3, '/test', 'test3')
@client.cancel
@client.close

data = r.read

Expand Down

0 comments on commit ca32197

Please sign in to comment.