Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTM Disconnect in State Disconnected Throws Error #842

Closed
10 tasks
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented pkg:rtm-api applies to `@slack/rtm-api`

Comments

@buildgreatthings
Copy link

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • [x ] question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • [ x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x ] I've read and agree to the Code of Conduct.
  • [x ] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/events-api
  • @slack/interactive-messages
  • [ x] @slack/rtm-api
  • @slack/webhooks
  • I don't know

Reproducible in:

package version:

node version:

OS version(s):

Steps to reproduce:

  1. Set up RTM, and start the app
  2. Try to run rtm.close() or rtm.disconnect()

Expected result:

RTM socket should close.

Actual result:

Error

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

@aoberoi aoberoi added needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info pkg:rtm-api applies to `@slack/rtm-api` labels Nov 16, 2019
@aoberoi
Copy link
Contributor

aoberoi commented Nov 16, 2019

Hi @awcchungster, thanks for reporting and sorry for the delay in our response.

I tried reproducing this problem but I wasn't able to. Can you provide any more information, or perhaps some sample code, to help us get to the bottom of this?

Here is what I tried:

const { RTMClient} = require('@slack/rtm-api');

const rtm = new RTMClient('xoxb-my-token');

// Start a connection and send a message
rtm.start();
rtm.sendMessage('hello', 'C123456');

// Attach a handler for when I press Ctrl+C in the terminal
process.on('SIGINT', () => {
  console.log('SIGINT received');
  rtm.disconnect().then(() => {
    console.log('disconnected');
  })
  .catch(console.error);
});

I run the program (with my bot token and a channel ID from my workspace substituted) and wait to see the message was sent (so that I know I'm connected). Then I press Ctrl+C on my keyboard to send the SIGINT signal. I see the SIGINT received line logged, and then see the disconnected line logged.

@Sorunome
Copy link

Hello, I am experiencing the same issue. When trying rtm.disconnect() the entire node process crashes with the following stacktrace:

/home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/StateMachine.js:76
      throw new Error('Unhandled event \'' + event + '\' in state \'' + this.currentState + '\'.');
      ^

Error: Unhandled event 'explicit disconnect' in state 'disconnected'.
    at StateMachine.handleUnhandledEvent (/home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/StateMachine.js:76:13)
    at /home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/HierarchicalStateMachine.js:79:33
    at TaskScheduler.execute (/home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/TaskScheduler.js:32:9)
    at TaskScheduler.enqueue (/home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/TaskScheduler.js:19:12)
    at HierarchicalStateMachine.handle (/home/sorunome/repos/soru-slack-client/node_modules/finity/lib/core/HierarchicalStateMachine.js:72:24)
    at WebSocket.<anonymous> (/home/sorunome/repos/soru-slack-client/node_modules/@slack/rtm-api/dist/RTMClient.js:405:77)
    at WebSocket.onClose (/home/sorunome/repos/soru-slack-client/node_modules/ws/lib/event-target.js:124:16)
    at WebSocket.emit (events.js:315:20)
    at WebSocket.emitClose (/home/sorunome/repos/soru-slack-client/node_modules/ws/lib/websocket.js:172:10)
    at TLSSocket.socketOnClose (/home/sorunome/repos/soru-slack-client/node_modules/ws/lib/websocket.js:781:15)
    at TLSSocket.emit (events.js:327:22)
    at net.js:674:12
    at TCP.done (_tls_wrap.js:563:7)

Not even a try....catch around the await rtm.disconnect() gets it to, well, not crash. I am trying to get a minimal working example for a crash currently, but it seems to be non-trivial

@Sorunome
Copy link

I figured out the issue, it appears to happen when you call rtm.disconnect() while the client is already disconnected - instead of crashing it is expected to do nothing.

const { RTMClient} = require('@slack/rtm-api');

const token = "xoxp-xxx"; // tested with a legacy xoxp token

const rtm = new RTMClient(token);

for (const evt of ["unable_to_rtm_start", "goodbye", "disconnected", "authenticated", "ready", "error", "bot_added", "bot_changed", "team_proifle_change", "team_pref_change", "user_typing", "presence_change"]) {
  rtm.on(evt, () => {
    console.log("Received " + evt);
  });
}

rtm.start();

process.on('SIGINT', () => {
  console.log('SIGINT received');
  rtm.disconnect().then(() => {
    rtm.disconnect();
    console.log('disconnected');
  })
  .catch(console.error);
});

@misscoded misscoded added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented and removed needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info labels Oct 15, 2020
@misscoded misscoded changed the title Slack RTM Library Unable to Close RTM Disconnect in State Disconnected Throws Error Oct 15, 2020
@seratch seratch added this to the [email protected] milestone Mar 25, 2021
filmaj added a commit that referenced this issue Mar 28, 2024
…transition back to disconnected. also add basic integration tests.
@filmaj
Copy link
Contributor

filmaj commented Mar 28, 2024

Hello after like, four years 👋

I have a fix for this teed up for the next major release, getting reviewed over here: #1764

@filmaj
Copy link
Contributor

filmaj commented Apr 1, 2024

This was fixed in v7 of rtm-api. Better (four years) late than never I guess!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented pkg:rtm-api applies to `@slack/rtm-api`
Projects
None yet
6 participants