RocketChat / hubot-rocketchat

Rocket.Chat Hubot adapter
MIT License
574 stars 227 forks source link

Unable to connect to Rocket Chat, seems useSsl is not being set right #316

Open suranc opened 5 years ago

suranc commented 5 years ago

I am trying to update the package.json in my base image to use 2.0.0 instead of 1.0.8, however it is unable to connect when I switch to 2.0.0. It seems that it might not be parsing the ROCKETCHAT_URL right or something, as my environment variable is set to use https, but useSsl is false in the logs.

Here is what I see when I try to run a container from my 2.0.0 image:

[Wed Apr 17 2019 00:43:30 GMT+0000 (Coordinated Universal Time)] INFO [connect] Connecting { host: 'rocketchat.nwie.net:443',
  useSsl: false,
  timeout: 20000 }
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] INFO [connect] Timeout (20000)
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR Unable to connect: {}
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR undefined
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR Unable to login: {}
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR undefined
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR Unable to join rooms: {}
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR undefined
[Wed Apr 17 2019 00:43:50 GMT+0000 (Coordinated Universal Time)] ERROR Unable to subscribe {}
(node:1) UnhandledPromiseRejectionWarning: Error: Asteroid connection timeout
    at Timeout._onTimeout (/opt/hubot/node_modules/@rocket.chat/sdk/dist/lib/driver.js:130:25)
    at listOnTimeout (timers.js:324:15)
    at processTimers (timers.js:268:5)

(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Looking at the code in ./@rocket.chat/sdk/dist/lib/driver.js:52 it seems that useSsl should be true, however it is false in the above log.

useSsl: ((process.env.ROCKETCHAT_URL || '').toString().startsWith('https')),

My environment variable definitely has https in it:

/opt/hubot # export|grep URL
export ROCKETCHAT_URL='https://rocketchat.nwie.net:443'

I have tried it without the :443 but that made no difference, and I am using exactly the same environment configuration between 1.0.8 and 2.0.0. I am launching this container via a Kubernetes helm chart I manage and using the same values file for each, just bumping my image version. The image using 1.0.8 works, but the one using 2.0.0 does not.

Here is the dependencies section from my new package.json using 2.0.0:

  "dependencies": {
    "hubot": "3.2.0",
    "hubot-help": "1.0.1",
    "hubot-rules": "1.0.0",
    "hubot-scripts": "2.17.2",
    "hubot-rocketchat": "2.0.0",
    "coffeescript": "2.3.2",
    "request": "2.88.0",
    "proxy-agent": "3.0.3"
  },
suranc commented 3 years ago

I figured this out, if you set the environment variable ROCKETCHAT_USESSL to true, then version 2.0.0 is able to connect over https. Still hitting problems with newer versions of Rocket.Chat related to #338, but that's due to the @rocket.chat/sdk which has a few PRs pending that can fix the issue. This environment variable fixes this specific issue.

I'm leaving it open because the repo still needs some documentation updates to make this clear, or a fix so it's no longer required. However, for the time being that environment variable works around this issue.