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

Hubot not compatible with versions >= 3.8.0 #19433

Closed
jadanah opened this issue Nov 2, 2020 · 16 comments · Fixed by #20801
Closed

Hubot not compatible with versions >= 3.8.0 #19433

jadanah opened this issue Nov 2, 2020 · 16 comments · Fixed by #20801

Comments

@jadanah
Copy link

jadanah commented Nov 2, 2020

Description:

Since upgrading Rocket Chat from 3.7.1 to 3.8.0-rc.2 the integration between rocket chat and our hubot instance no longer works. Every time the bot receives a message the following exception is thrown ERROR TypeError: Cannot read property '_id' of undefined (see below).

I have replicated this by creating a new basic project with only the dependencies below and run the command hubot ping and will still get the below exception.

Steps to reproduce:

  1. Create basic hubot app with dependencies listed below,
  2. Start hubot using the rocketchat adaptor
  3. DM bot hubot ping

Expected behavior:

Receive response: Pong

Actual behavior:

No response

Server Setup Information:

  • Version of Rocket.Chat Server: 3.8.0-rc.2
  • Operating System: Ubuntu 20.04.1 LTS
  • Deployment Method: Manual
  • Number of Running Instances: `
  • DB Replicaset Oplog: Yes
  • NodeJS Version: v12.18.4
  • MongoDB Version: v4.0.21

Client Setup Information

  • Desktop App or Browser Version: 3.0.5
  • Operating System: Windows 10 (19041.610)

Additional context

From package.json

  "dependencies": {
    "hubot-diagnostics": "^1.0.0",
    "hubot-help": "^1.0.1",
    "hubot": "^3.3.2",
    "hubot-rocketchat": "2.0.0"
  }

Relevant logs:

[Mon Nov 02 2020 11:05:05 GMT+0000 (Greenwich Mean Time)] ERROR TypeError: Cannot read property '_id' of undefined
at Object. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\hubot-rocketchat\[email protected]\sdk\dist\lib\driver.js:374:23)
at Generator.next (:null:null)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\hubot-rocketchat\[email protected]\sdk\dist\lib\driver.js:7:71
at new Promise (:null:null)
at __awaiter (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\hubot-rocketchat\[email protected]\sdk\dist\lib\driver.js:3:12)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\hubot-rocketchat\[email protected]\sdk\dist\lib\driver.js:368:45
at ReactiveQuery. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\hubot-rocketchat\[email protected]\sdk\dist\lib\driver.js:344:17)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:170:12
at Array.forEach (:null:null)
at ReactiveQuery._emit (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:169:22)
at Set. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:749:8)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:170:12
at Array.forEach (:null:null)
at Set._emit (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:169:22)
at Set.put (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:965:7)
at Set. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:1020:8)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:170:12
at Array.forEach (:null:null)
at Set._emit (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:169:22)
at Set.put (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:965:7)
at Collection._remoteToLocalUpdate (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:695:12)
at Asteroid._onChanged (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:453:36)
at DDP. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\asteroid\dist\asteroid.node.js:392:8)
at D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\ddp.js\src\ddp.js:125:12
at Array.forEach (:null:null)
at DDP._emit (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\ddp.js\src\ddp.js:124:22)
at DDP._on_changed (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\ddp.js\src\ddp.js:248:8)
at DDP._on_socket_message (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\ddp.js\src\ddp.js:326:26)
at Client.dispatchEvent (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\faye-websocket\lib\faye\websocket\api\event_target.js:24:30)
at Client._receiveMessage (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\faye-websocket\lib\faye\websocket\api.js:152:10)
at Client. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\faye-websocket\lib\faye\websocket\api.js:36:49)
at Client.emit (node:events:339:22)
at Client. (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\driver\hybi.js:460:14)
at pipe (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-extensions\lib\pipeline\index.js:37:40)
at Pipeline._loop (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-extensions\lib\pipeline\index.js:44:3)
at Pipeline.processIncomingMessage (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-extensions\lib\pipeline\index.js:13:8)
at Extensions.processIncomingMessage (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-extensions\lib\websocket_extensions.js:133:20)
at Client._emitMessage (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\driver\hybi.js:451:22)
at Client._emitFrame (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\driver\hybi.js:411:19)
at Client.parse (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\driver\hybi.js:137:18)
at Client.parse (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\driver\client.js:63:58)
at IO.write (D:\ProgramData\SF2\vm0\Fabric\work\Applications\BotsType_App14\HubotPkg.Code.39.2.1-ci.18357\node_modules\websocket-driver\lib\websocket\streams.js:80:16)
at Socket.ondata (node:internal/streams/readable:715:22)
at Socket.emit (node:events:327:20)
at addChunk (node:internal/streams/readable:304:12)
at readableAddChunk (node:internal/streams/readable:279:9)
at Socket.Readable.push (node:internal/streams/readable:218:10)
at TCP.onStreamRead (node:internal/stream_base_commons:192:23)

@jadanah
Copy link
Author

jadanah commented Nov 2, 2020

To replicate use the sample project from https://github.com/RocketChat/hubot-rocketchat-boilerplate but I can confirm that my previous setup was working fine until 3.8.0

@jadanah
Copy link
Author

jadanah commented Nov 3, 2020

It seems that the message passed to reactToMessages is now an array causing the issue I've managed to work around this by adding message = message.slice(0,1).shift(); which seems to have resolved the issue but obviously this is not a valid solution.

@rocket.chat\sdk\dist\lib\driver.js

function respondToMessages(callback, options = {}) {
    const config = Object.assign({}, respondDefaults(), options);
    exports.lastReadTime = new Date(); // init before any message read
    reactToMessages((err, message, meta) => __awaiter(this, void 0, void 0, function* () {
        if (err) {
            log_1.logger.error(`Unable to receive messages ${JSON.stringify(err)}`);
            callback(err); // bubble errors back to adapter
        }

        // ****** ADDING THIS HERE RESOLVES THE ISSUE *****
        message = message.slice(0,1).shift();

        // Ignore bot's own messages
        if (message.u._id === exports.userId)
            return;
        // Ignore DMs if configured to
        const isDM = meta.roomType === 'd';
        if (isDM && !config.dm)
            return;
        // Ignore Livechat if configured to
        const isLC = meta.roomType === 'l';
        if (isLC && !config.livechat)
            return;
        // Ignore messages in public rooms not joined by bot if configured to
        if (!config.allPublic && !isDM && !meta.roomParticipant)
            return;
        // Set current time for comparison to incoming
        let currentReadTime = new Date(message.ts.$date);
        // Ignore edited messages if configured to
        // unless it's newer than current read time (hasn't been seen before)
        // @todo: test this logic, why not just return if edited and not responding
        if (config.edited && typeof message.editedAt !== 'undefined') {
            let edited = new Date(message.editedAt.$date);
            if (edited > currentReadTime)
                currentReadTime = edited;
        }
        // Ignore messages in stream that aren't new
        if (currentReadTime <= exports.lastReadTime)
            return;
        // At this point, message has passed checks and can be responded to
        log_1.logger.info(`Message receive callback ID ${message._id} at ${currentReadTime}`);
        log_1.logger.info(`[Incoming] ${message.u.username}: ${(message.file !== undefined) ? message.attachments[0].title : message.msg}`);
        exports.lastReadTime = currentReadTime;
        // Add room name to meta, is useful for some adapters
        if (!isDM && !isLC)
            meta.roomName = yield getRoomName(message.rid);
        // Processing completed, call callback to respond to message
        callback(null, message, meta);
    }));
}
exports.respondToMessages = respondToMessages;

@jadanah jadanah changed the title Hubot not compatible with 3.8.0-rc.2 Hubot not compatible with 3.8.0-rc.11 Nov 13, 2020
@jadanah
Copy link
Author

jadanah commented Nov 13, 2020

Tested against 3.8.0-rc.11 and issue still remains

@jadanah jadanah changed the title Hubot not compatible with 3.8.0-rc.11 Hubot not compatible with 3.8.0 Nov 17, 2020
@jadanah
Copy link
Author

jadanah commented Nov 17, 2020

Tested against 3.8.0 release and its still the same.

@ataraxus
Copy link

Can confirm issue(#19567)... impacts production systems of ours...

@brunobertoldi
Copy link

Can confirm.
It was working with 3.7.X and stopped working after the 3.8.0 upgrade.

@rogerpfaff
Copy link

It's broken in 3.9.0 too.

@cnvx
Copy link

cnvx commented Dec 2, 2020

+1 hubot isn't working on our 3.9.0 instance, relevant logs (from hubot docker):

[Wed Dec 02 2020 12:18:28 GMT+0000 (GMT)] ERROR TypeError: Cannot read property '_id' of undefined
    at /home/hubot/node_modules/hubot-rocketchat/src/rocketchat.js:193:27
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/src/rocketchat_driver.js:231:22)
    at /home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:170:12
    at Array.forEach (native)
    at [object Object].Asteroid.utils.EventEmitter._emit (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:169:22)
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:749:8)
    at /home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:170:12
    at Array.forEach (native)
    at [object Object].Asteroid.utils.EventEmitter._emit (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:169:22)
    at [object Object].Set.put (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:965:7)
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:1020:8)
    at /home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:170:12
    at Array.forEach (native)
    at [object Object].Asteroid.utils.EventEmitter._emit (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:169:22)
    at [object Object].Set.put (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:965:7)
    at [object Object].Collection._remoteToLocalUpdate (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:695:12)
    at [object Object].Asteroid._onChanged (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:453:36)
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/dist/asteroid.node.js:392:8)
    at /home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/ddp.js/src/ddp.js:125:12
    at Array.forEach (native)
    at [object Object].DDP._emit (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/ddp.js/src/ddp.js:124:22)
    at [object Object].DDP._on_changed (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/ddp.js/src/ddp.js:248:8)
    at [object Object].DDP._on_socket_message (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/ddp.js/src/ddp.js:326:26)
    at [object Object].EventTarget.dispatchEvent (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/lib/faye/websocket/api/event_target.js:22:30)
    at [object Object].instance._receiveMessage (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/lib/faye/websocket/api.js:150:10)
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/lib/faye/websocket/api.js:34:49)
    at emitOne (events.js:82:20)
    at [object Object].emit (events.js:169:7)
    at [object Object].<anonymous> (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:451:14)
    at pipe (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:37:40)
    at [object Object].Pipeline._loop (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:44:3)
    at [object Object].Pipeline.processIncomingMessage (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/pipeline/index.js:13:8)
    at [object Object].instance.processIncomingMessage (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/node_modules/websocket-extensions/lib/websocket_extensions.js:133:20)
    at [object Object].instance._emitMessage (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:442:22)
    at [object Object].instance._emitFrame (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:405:19)
    at [object Object].instance.parse (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/hybi.js:141:18)
    at [object Object].instance.parse (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/driver/client.js:62:58)
    at [object Object].IO.write (/home/hubot/node_modules/hubot-rocketchat/node_modules/asteroid/node_modules/faye-websocket/node_modules/websocket-driver/lib/websocket/streams.js:80:16)
    at Socket.ondata (_stream_readable.js:542:20)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)
    at TCP.onread (net.js:540:20)

@garthh
Copy link

garthh commented Dec 12, 2020

some news about this error ?

@ataraxus
Copy link

no, still broken with 3.9.1

@andre77
Copy link

andre77 commented Dec 18, 2020

its actually sort of a disaster, our bots (hubot, botkit) are not able to work properly since the server upgrade to 3.9.1
any suggestions, when to expect a fix or at least a work around ?
many thanks in advance

@jadanah jadanah changed the title Hubot not compatible with 3.8.0 Hubot not compatible with versions >= 3.8.0 Dec 18, 2020
@jadanah
Copy link
Author

jadanah commented Dec 18, 2020

See RocketChat/Rocket.Chat.js.SDK#122 for workaround

@rogerpfaff
Copy link

That is not even remotely a workaround if you don't know nothing about development inside RocketChat. I could not find the mentioned file so I can not fix this. Either somebody should write a better documentation for the workaround or much better just fix what was broken without further notice.

@slyk
Copy link

slyk commented Dec 21, 2020

That is not even remotely a workaround if you don't know nothing about development inside RocketChat. I could not find the mentioned file so I can not fix this. Either somebody should write a better documentation for the workaround or much better just fix what was broken without further notice.

Nobody should, but you could ask for help, that what internet is used sometimes :)

I'm dealling with this right now, so if you have Ubuntu/Debian this should work:

  1. You have access to your server with rocketchat bot service is running using ssh. Most of the times you should connect usinf terminal (ctrl+t):
    ssh [email protected]
    (change to your IP address)

  2. Search for the file with problem using:
    grep -r "if (message.u._id === exports.userId)" /home
    You will see the address of the driver.js file. Most of the times it somewhere in /home directory, but if you don't find it there, you can replace "/home" to "/var" or just "/" to search everywhere.

  3. Change file, if it is in home, you should have access and edit right to that file, so you can edit using "nano":
    nano /home/toopro/hubot/bots-hubot/node_modules/@rocket.chat/sdk/dist/lib/driver.js
    This my address, change to yours. If it will be read only, try prefix this command with "sudo"

  4. Find the line. Pressing "ctrl+W" and fill search string as "message.u._id", press enter. you should see the code:

if (err) {
            log_1.logger.error(`[received] Unable to receive: ${err.message}`);
            callback(err); // bubble errors back to adapter
        }

        // Ignore bot's own messages
        if (message.u._id === exports.userId)
            return;
  1. Add given code before the "// Ignore bot..." line:
    message = Array.isArray(message) ? message[0] : message;

  2. Save the file pressing "ctrl+O". It will ask you the filename, just press enter to save with the same name (rewrite).

  3. Finally the system need to use your new file, so you need to restart hubot service, it depends how you named it, in my system I do:
    sudo service tps-hubot restart

@rogerpfaff
Copy link

Thanks for the comprehensive guide and sorry for my rude words before. Sometimes just asking is out of range when in rage too much. :) ☮️

@Falco20019
Copy link

Falco20019 commented Jun 17, 2021

@ggazzo I have a similar issue by upgrading from 3.11.0 to 3.15.0, but due to the docker image having message = message.shift() there which also fails. I applied the patch to my driver by patching the file into the container. So no it's working with either version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants