Skip to content

Stop Bluebird promise created but not returned warning when sending a message in a room

Stop Bluebird promise created but not returned warning when sending a message in a room (around the Gitter Matrix bridge).

Learned that I need to check up, down, and around the stack trace given to see where you forgot to return the promise. This one wasn't as obvious to me and thought it was possibly a problem with Mongoose itself which people have found problems in around the callbacks -> https://stackoverflow.com/q/39135678/796832 - That issue also mentions mongoose/lib/query.js which matched my stack trace so it seemed applicable.

The problem ended up being the the async onDataChange which is used as an event listener -> modules/matrix-bridge/lib/gitter-bridge.js#L25-29. That actual problem spot isn't even listed in the stack trace. The async function(which returns a promise behind the scenes) doesn't like getting fired and forgotten as a callback.


The trace is very sparse and doesn't give enough info by default:

$ npm start

...
// Send a message in a room bridged to Matrix

(node:13460) Warning: a promise was created in a handler at domain.js:126:23 but was not returned from it, see http://goo.gl/rRqMUw
    at new Promise (C:\Users\MLM\Documents\GitLab\webapp\node_modules\bluebird\js\release\promise.js:103:10)

But if you add --trace-warnings to the Node.js process, it gives the full stack trace. I added the --trace-warnings-node option to our start utility which will add --trace-warnings to the Node.js process. Similar to what we already do for the --inspect flag.

$ npm start -- --trace-warnings-node

...
// Send a message in a room bridged to Matrix

(node:16928) Warning: a promise was created in a handler at domain.js:126:23 but was not returned from it, see http://goo.gl/rRqMUw
    at new Promise (C:\Users\MLM\Documents\GitLab\webapp\node_modules\bluebird\js\release\promise.js:103:10)
    at model.Query.exec (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\lib\query.js:2294:17)
    at Object.findById (C:\Users\MLM\Documents\GitLab\webapp\modules\rooms\lib\troupe-service.js:44:42)
    at isGitterRoomIdAllowedToBridge (C:\Users\MLM\Documents\GitLab\webapp\modules\matrix-bridge\lib\gitter-utils.js:21:42)
    at GitterBridge.handleChatMessageCreateEvent (C:\Users\MLM\Documents\GitLab\webapp\modules\matrix-bridge\lib\gitter-bridge.js:85:35)
    at GitterBridge.onDataChange (C:\Users\MLM\Documents\GitLab\webapp\modules\matrix-bridge\lib\gitter-bridge.js:44:22)
    at EventEmitter.emit (events.js:203:15)
    at EventEmitter.emit (domain.js:448:20)
    at Object.dataChange2 (C:\Users\MLM\Documents\GitLab\webapp\modules\appevents\lib\app-events.js:137:25)
    at Object.<anonymous> (C:\Users\MLM\Documents\GitLab\webapp\server\services\live-collection-handlers\live-collection-chats.js:12:15)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:126:23)
From previous event:
    at serializeChatToRoom (C:\Users\MLM\Documents\GitLab\webapp\server\services\live-collection-handlers\live-collection-chats.js:11:57)
    at Object.create (C:\Users\MLM\Documents\GitLab\webapp\server\services\live-collection-handlers\live-collection-chats.js:18:12)
    at EventEmitter.<anonymous> (C:\Users\MLM\Documents\GitLab\webapp\server\services\live-collection-handlers\index.js:46:46)
    at EventEmitter.emit (events.js:198:13)
    at EventEmitter.emit (domain.js:448:20)
    at Object.onCreate (C:\Users\MLM\Documents\GitLab\webapp\server\services\persistence-service-events.js:28:29)
    at model.<anonymous> (C:\Users\MLM\Documents\GitLab\webapp\modules\persistence-utils\lib\mongoose-utils.js:99:46)
    at model.<anonymous> (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\lib\schema.js:1100:8)
    at next_ (C:\Users\MLM\Documents\GitLab\webapp\node_modules\hooks-fixed\hooks.js:86:35)
    at fnWrapper (C:\Users\MLM\Documents\GitLab\webapp\node_modules\hooks-fixed\hooks.js:186:8)
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\lib\model.js:3388:16
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\lib\model.js:233:5
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\lib\model.js:139:7
    at timingCallback (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongodb-perf-wrapper\lib\wrap.js:69:37)
    at timingCallback (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongodb-perf-wrapper\lib\wrap.js:69:37)
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\collection.js:523:5
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\collection.js:701:5
    at handleCallback (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\utils.js:96:56)
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\bulk\unordered.js:473:9
    at handleCallback (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\utils.js:96:56)
    at resultHandler (C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb\lib\bulk\unordered.js:420:5)
    at C:\Users\MLM\Documents\GitLab\webapp\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:455:18
    at process._tickCallback (internal/process/next_tick.js:61:11)
Edited by Eric Eastwood

Merge request reports