Rocket.chat: Rocket crash with TypeError: host.endsWith is not a function

Created on 21 Sep 2016  Β·  13Comments  Β·  Source: RocketChat/Rocket.Chat

Your Rocket.Chat version: 0.40 with Node 4.5

Rocket crash few seconds after startup with this error message :

Updating process.env.MAIL_URL
ufs: store created at
{"line":"114","file":"migrations.js","message":"Migrations: Not migrating, already at version 61","time":{"$date":1474475977793},"level":"info"}
Updating process.env.MAIL_URL
Using GridFS for custom emoji storage
Using GridFS for Avatar storage
βž” System βž” startup
βž” +---------------------------------------------+
βž” | SERVER RUNNING |
βž” +---------------------------------------------+
βž” | |
βž” | Version: 0.40.0 |
βž” | Process Port: 3000 |
βž” | Site URL: https://blah.blah.blah |
βž” | |
βž” +---------------------------------------------+
tls.js:132
if (!host || !host.endsWith('.')) host += '.';
^

TypeError: host.endsWith is not a function
at Object.checkServerIdentity (tls.js:132:24)
at TLSSocket. (_tls_wrap.js:1028:29)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:586:8)
at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:428:38)

bug

Most helpful comment

I had the same behaviour, the workaround is a one-line patch:

--- a/packages/rocketchat-ldap/server/ldap.js   2016-09-26 22:29:52.879794680 +0200
+++ b/packages/rocketchat-ldap/server/ldap.js   2016-09-26 22:30:12.822848111 +0200
@@ -102,7 +102,7 @@
            // Set host parameter for tls.connect which is used by ldapjs starttls. This shouldn't be needed in newer nodejs versions (e.g v5.6.0).
            // https://github.com/RocketChat/Rocket.Chat/issues/2035
            // https://github.com/mcavage/node-ldapjs/issues/349
-           tlsOptions.host = [self.options.host];
+           tlsOptions.host = self.options.host;

            logger.connection.info('Starting TLS');
            logger.connection.debug('tlsOptions', tlsOptions);

All 13 comments

@michaudg we are sorry to hear that you have a problem, but could you give us more info about your setup?

Rocket version is 0.40.1.
node -v : v4.5.0
Ubuntu 16.04.1
MongoDB 3.2.9
Rocket is behind a nginx proxy with SSL.
My Rocket URL starts with https://
Rocket started wth pm2 start [...]

The server can run correctly for few seconds but I think that as soon as the endsWith function is called, the server crash and restart.
This problem happenned when I upgraded from 0.39 to 0.40.

The err.log is filled with :
TypeError: host.endsWith is not a function
at Object.checkServerIdentity (tls.js:132:24)
at TLSSocket. (_tls_wrap.js:1028:29)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:586:8)
at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:428:38)

The problem comes from the Rocket.Chat.Electron desktop client.
As soon as a connection is initiated by the client, the server crash with the endsWith error.

Confirming this crash with RC 0.40.1 (tested with nodejs 4.5 and 6.6).

Not sure if it's attributable to the electron client : we have at least 1 electron client open without crash ; the crash seems to occur at any login/authentication request (i.e. also when initiated from a browser session).

Confirmed that this happens as soon as a login request/retry is initiated (from a browser client).

Disabling LDAP (by reassigning the LDAP server ip to 127.0.0.1 in /etc/hosts) allows us to login with the RC admin credentials.

Changing the encryption type in the LDAP settings from "StartTLS" to "SSL/LDAPS" revents RC from crashing.

I am having the same issue I think. I use nginx for SSL proxy to RocketChat, and OpenLDAP for auth (StartTLS). This was mostly working before updating the docker image today to :latest . Crashes upon login. Full disclosure, both my Nginx cert and my LDAP TLS cert are signed by my corporate CA, the Root cert of which wouldnt be trusted by anything in the Rocket Chat docker image because I havent shimmed it into the image. But it was working with previous docker image.

rocketchat_1 | βž” +------------------------------------------------+
rocketchat_1 | βž” | SERVER RUNNING |
rocketchat_1 | βž” +------------------------------------------------+
rocketchat_1 | βž” | |
rocketchat_1 | βž” | Version: 0.40.1 |
rocketchat_1 | βž” | Process Port: 3000 |
rocketchat_1 | βž” | Site URL: https://rocket.**.com |
rocketchat_1 | βž” | |
rocketchat_1 | βž” +------------------------------------------------+
rocketchat_1 | tls.js:132
rocketchat_1 | if (!host || !host.endsWith('.')) host += '.';
rocketchat_1 | ^
rocketchat_1 |
rocketchat_1 | TypeError: host.endsWith is not a function
rocketchat_1 | at Object.checkServerIdentity (tls.js:132:24)
rocketchat_1 | at TLSSocket. (_tls_wrap.js:1028:29)
rocketchat_1 | at emitNone (events.js:67:13)
rocketchat_1 | at TLSSocket.emit (events.js:166:7)
rocketchat_1 | at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:586:8)
rocketchat_1 | at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:428:38)

@didierm LDAP/StartTLS here too. Changing to SSL/LDAPS seems to be good.
Thanks for your solution.

Service crashes continuously after upgrading to 0.40.1 (from 0.37)

Sep 26 10:55:11  RocketChat: rocketchat:ldap ldap.js:47 #033[34mLDAP Òž” Connection.info#033[39m Init setup
Sep 26 10:55:11  RocketChat: rocketchat:ldap ldap.js:85 #033[34mLDAP Òž” Connection.info#033[39m Connecting ldap://our.ldap.server:389
Sep 26 10:55:11  RocketChat: rocketchat:ldap ldap.js:86 #033[34mLDAP Òž” Connection.debug#033[39m connectionOptions { url: 'ldap://our.ldap.server:389',
Sep 26 10:55:11  RocketChat: timeout: 600000,
Sep 26 10:55:11  RocketChat: connectTimeout: 10000,
Sep 26 10:55:11  RocketChat: idleTimeout: 10000,
Sep 26 10:55:11  RocketChat: reconnect: false }
Sep 26 10:55:11  RocketChat: rocketchat:ldap ldap.js:107 #033[34mLDAP Òž” Connection.info#033[39m Starting TLS
Sep 26 10:55:11  RocketChat: rocketchat:ldap ldap.js:108 #033[34mLDAP Òž” Connection.debug#033[39m tlsOptions { rejectUnauthorized: true,
Sep 26 10:55:11  RocketChat: ca: [ '-----BEGIN CERTIFICATE-----\n***DELETED***\n-----END CERTIFICATE-----' ],
Sep 26 10:55:11  RocketChat: host: [ 'our.ldap.server' ] }
Sep 26 10:55:11  RocketChat: tls.js:132
Sep 26 10:55:11  RocketChat: if (!host || !host.endsWith('.')) host += '.';
Sep 26 10:55:11  RocketChat: ^
Sep 26 10:55:11  RocketChat: TypeError: host.endsWith is not a function
Sep 26 10:55:11  RocketChat: at Object.checkServerIdentity (tls.js:132:24)
Sep 26 10:55:11  RocketChat: at TLSSocket.<anonymous> (_tls_wrap.js:1028:29)
Sep 26 10:55:11  RocketChat: at emitNone (events.js:67:13)
Sep 26 10:55:11  RocketChat: at TLSSocket.emit (events.js:166:7)
Sep 26 10:55:11  RocketChat: at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:586:8)
Sep 26 10:55:11  RocketChat: at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:428:38)
Sep 26 10:55:12  systemd: rocketchat.service: main process exited, code=exited, status=1/FAILURE
Sep 26 10:55:12  systemd: Unit rocketchat.service entered failed state.
Sep 26 10:55:12  systemd: rocketchat.service failed.

Switching encryption to SSL/LDAP and changing the port to 636 works for now.

I had the same behaviour, the workaround is a one-line patch:

--- a/packages/rocketchat-ldap/server/ldap.js   2016-09-26 22:29:52.879794680 +0200
+++ b/packages/rocketchat-ldap/server/ldap.js   2016-09-26 22:30:12.822848111 +0200
@@ -102,7 +102,7 @@
            // Set host parameter for tls.connect which is used by ldapjs starttls. This shouldn't be needed in newer nodejs versions (e.g v5.6.0).
            // https://github.com/RocketChat/Rocket.Chat/issues/2035
            // https://github.com/mcavage/node-ldapjs/issues/349
-           tlsOptions.host = [self.options.host];
+           tlsOptions.host = self.options.host;

            logger.connection.info('Starting TLS');
            logger.connection.debug('tlsOptions', tlsOptions);

Is there any progress on this? I've been manually applying the above patch for a few releases now.

@bartbes I tested your patch and confirm it helps. Perhaps you could try to submit pull request to upstream? :)
Stealing credit from you dosn't seem nice :)

Was this page helpful?
0 / 5 - 0 ratings