cloudant / nodejs-cloudant

Cloudant Node.js client library
Apache License 2.0
255 stars 90 forks source link

Unhandled promise rejection with `Error: Callback was already called.` #454

Closed ricellis closed 3 years ago

ricellis commented 3 years ago

Bug Description

Customer reported an unhandled promise rejection:

Error: Callback was already called.
    at /opt/app-root/src/node_modules/async/dist/async.js:985:32
    at updateState (/opt/app-root/src/node_modules/@cloudant/cloudant/lib/clientutils.js:53:3)
    at /opt/app-root/src/node_modules/@cloudant/cloudant/lib/clientutils.js:142:11
    at /opt/app-root/src/node_modules/@cloudant/cloudant/plugins/iamauth.js:88:7

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

The problem was reported from a production app without debug enabled. Only the iamauth plugin is active.

2. What you expected to happen

One callback at the completion of the plugin async eachseries.

3. What actually happened

Two callbacks. Based on the stack my best guess is that it is possible for an error during a success callback to cause an error that will in turn be caught by the promise chain and trigger a second callback.

Environment details