axios: Axios causes node.exe to crash without possibility to catch the exception

Describe the bug

Axios v.0.21.0 causes node.exe to silently crash, without possibility to catch the exception. Occurs with node.js v.14.15.0 (current LTS Version, recommended for most users). Earlier or later versions works Ok (I have tested v.9.11.1 and v.15.1.0) Update: Node v.9.11.1 also crashing in the similar way (on Windows Server 2016 v.1607) Update 2: Basic Auth causes the crashing. Requests without authorization works ok so far Update 3: Node v.14.15.1 also crashing in the similar way

To Reproduce

Effect is not stable and not easy to be quickly reproduced, appears mostly on bad/slow internet connections. Most probably because of “connect ETIMEDOUT”, but this is only my guessing, because node.exe just unexpectedly terminates, without any additional info.

// This is example code for reproducing the problem. Actually nothing special, just continuously getting lots of data. 
// Size of retrieved files is not important (from several kilobytes to several megabytes)
// MyApi is url/config of service-now.com REST API. Unfortunately I can’t share it.
var axios = require('axios');
let n=1;
test();
async function test() {
  do {
    await axios.get(MyApiUrl,MyApiConfig)
      .then(res => console.log(n++, "got "+JSON.stringify(res.data).length+" bytes (node.js "+process.version+")"))
      .catch(err => {console.error("ERROR: "+err.message);process.exit()})
  } while (true)
};

Expected behavior

Even on more or less normal internet connection node.exe crashes within getting of one or two gigabytes of data (in summary, by portions, not at once). Choosing bad internet connection will bring the same result faster.

Environment

  • Axios Version 0.21.0
  • Node.js Versions 14.15.0, 14.15.1, v.9.11.1
  • OS: Windows 10 v.1909 and 2004, and Windows Server 2016 v.1607

Additional context/Screenshots

N/A

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 21 (5 by maintainers)

Commits related to this issue

Most upvoted comments

The error is still repeating. Node.js v18.4.0 Axios 1.2.0

Example code:

async function createRequest(options) {
    try {
        let response = await axios(options);
        return response;
    } catch (e) {
        console.log(e);
        return null;
    }
}

The console outputs an error from the catch block, but then Nodejs crashes with “UnhandledPromiseRejection” error

I have same issue. The catch block worked expected but then Node Process crashed with error below. I used axios.create and specified the timeout configuration. Seems error throw from setTimeout cannot be catched. But I cannot reproduce it locally.

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
Error: timeout of 10000ms exceeded
    at createError (/workspace/api-service/srv/main.cjs:87147:20)
    at RedirectableRequest.handleRequestTimeout (/workspace/api-service/srv/main.cjs:87815:20)
    at RedirectableRequest.emit (node:events:513:28)
    at Timeout.<anonymous> (/workspace/api-service/srv/main.cjs:64949:17)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7) {

Still encountering this with Axios 1.1.3 intermittently in Azure Functions.

I don’t have enough of a reproduction path to open a new issue, but I still run into this problem with axios v0.27.2 on node v16.15.1. I found out that while awaiting my axios.post in my case process.on('beforeExit',...) gets triggered, which is an indication that there’s no crash going on, but that the event loop is just empty. Apparently Axios is doing nothing anymore 😃.

Not sure it has anything to do with it, but if I remove 'Accept-Encoding': 'gzip' from my headers, the problem also disappears.

I can reproduce the issue on macOS, ubuntu and node 14.18. The same code works on node v16+ throwing the stacktrace below

Error: aborted
    at connResetException (node:internal/errors:691:14)
    at TLSSocket.socketCloseListener (node:_http_client:407:19)
    at TLSSocket.emit (node:events:402:35)
    at node:net:687:12
    at TCP.done (node:_tls_wrap:580:7)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

while in node 14 it fails in the async_hook callbackTrampoline while calling the callback.apply. the cb argument is undefined (asyncId = 0)

function callbackTrampoline(asyncId, resource, cb, ...args) {
  const index = async_hook_fields[kStackLength] - 1;
  execution_async_resources[index] = resource;

  if (asyncId !== 0 && hasHooks(kBefore))
    emitBeforeNative(asyncId);

  let result;
  if (asyncId === 0 && typeof domain_cb === 'function') {
    args.unshift(cb);
    result = domain_cb.apply(this, args);
  } else {
   ==> result = cb.apply(this, args);
  }

  if (asyncId !== 0 && hasHooks(kAfter))
    emitAfterNative(asyncId);

  execution_async_resources.pop();
  return result;
}

not sure what happens inside nodejs but that is caused at this point on aborted connection errors as the node16 stacktrace can show. Hope that can help someone else as I spent hours before finding this thread and understanding why my promises were not resolved/rejected…