asterisk / node-ari-client

Node.js client for ARI. This library is best effort with limited support.
Other
250 stars 98 forks source link

Debugging unhandled rejections in node ari #91

Closed jp1987 closed 6 years ago

jp1987 commented 6 years ago

I have a node ari app that handles thousands of calls a day. About once a day, I see an unhandled rejection. I added the following code:

process.on('unhandledRejection', function(reason, p) {
    console.log('UNHANDLED_REJECTION');
    console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});

This is the output:

Unhandled Rejection at: Promise Promise {
  _bitField: 136839168,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _progressHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _settledValue:
   Error: {
     "message": "Channel not found"
   }
       at SwaggerRequest.swaggerError [as errorCallback] (/home/didux/api/node_modules/ari-client/lib/resources.js:944:19)
       at Object.error (/home/didux/api/node_modules/swagger-client/lib/swagger.js:1077:24)
       at EventEmitter.error (/home/didux/api/node_modules/swagger-client/lib/swagger.js:1296:19)
       at emitOne (events.js:96:13)
       at EventEmitter.emit (events.js:188:7)
       at emit (/home/didux/api/node_modules/shred/lib/shred/request.js:454:21)
       at /home/didux/api/node_modules/shred/lib/shred/request.js:473:9
       at setBodyAndFinish (/home/didux/api/node_modules/shred/lib/shred/response.js:103:7)
       at IncomingMessage.<anonymous> (/home/didux/api/node_modules/shred/lib/shred/response.js:120:7)
       at emitNone (events.js:91:20)
       at IncomingMessage.emit (events.js:185:7)
       at endReadableNT (_stream_readable.js:974:12)
       at _combinedTickCallback (internal/process/next_tick.js:80:11)
       at process._tickCallback (internal/process/next_tick.js:104:9) } reason: Error: {
  "message": "Channel not found"
}

I suspect we are trying to execute an action on a channel that has already been hung up/destroyed. Because it only happens once every couple of thousand calls, it's pretty much impossible to reproduce this on a development environment.

How do I best debug this? It would be good to see the action that was being executed. I am using callbacks in my code, no promises.

samuelg commented 6 years ago

That happens whenever the other side hangs up while you are interacting with the channel in ARI and can be handled by adding clean up logic in a ChannelDestroyed or StasisEnd event for that channel.

There's no easy way to figure out which action lead to the error above I'm afraid. If you want to know where it's originating from you'll have to add error handler callbacks where you call actions and add logging information to determine where the culprit is.

jp1987 commented 6 years ago

Right, will do. Thanks!

awsomedesigner commented 1 year ago

Hey, i get same err, you can describe more about solution.

awsomedesigner commented 1 year ago

Hey, i get same err, you can describe more about solution.

Your Help appreciated.