Skip to content

Events are fired twice after a disconnection #362

Closed
@ThHareau

Description

I'm having an issue where my bot is sending several time the same message after a disconnection.

How to reproduce:

Here is a sample of my code:

realtime_client = Slack::RealTime::Client.new token: token,
    websocket_ping: 3 # to fasten the deconnection detection, but not needed to triger the bug

realtime_client.on :hello do
  puts 'Ready to go!'
end

realtime_client.on :message do |message|
  puts 'triggered' if message.text == 'My message'
end

realtime_client.start!

Then, launch the bot, trigger it: one message should happen.

Disconnect your laptop from internet, wait for the warning to come (so that the bot detects the deconnection) and reconnect.
Trigger the bot: it should be triggered twice instead of once.

My logs:

Ready to go!
triggered
W, [2021-01-29T19:01:23.481714 #87339]  WARN -- id=T03L75GUK, name=__, domain=__: is offline
W, [2021-01-29T19:01:24.484552 #87339]  WARN -- id=T03L75GUK, name=__, domain=__: is offline
Ready to go!
triggered
triggered

Hack

Disabling websocket pings fixes the issue:

realtime_client = Slack::RealTime::Client.new token: token, websocket_ping: 0

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions