#1801·superagent

"superagent: double callback bug" with timeout

Author: gramakriCreated Apr 23, 2024Updated Apr 23, 2024
LabelsBug

Describe the bug

Node.js version: v18.16.0

OS version: ubuntu 22.04

Description: When a request aborts with a timeout, it calls the callback twice resulting in a message being printed on the console "superagent: double callback bug"

Expected behavior

Should not print the console message and should not call the callback twice

Code to reproduce

const superagent = require('superagent');

(async function () {
    try {
        await superagent.get('https://some/slow/api').timeout(20000);
    } catch (error) {
        console.log(error);
    }
})();

Output (with DEBUG=*) :

  superagent GET https://some/slow/api +0ms
  superagent GET https://some/slow/api -> 200 +5s

Error: Timeout of 20000ms exceeded
    at RequestBase._timeoutError (/home/yellowtent/box/node_modules/superagent/lib/request-base.js:712:17)
    at Timeout.<anonymous> (/home/yellowtent/box/node_modules/superagent/lib/request-base.js:727:12)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7) {
  timeout: 20000,
  code: 'ECONNABORTED',
  errno: 'ETIME',
  response: undefined
}
superagent: double callback bug

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.