koajs / discussions

KoaJS Discussions
2 stars 2 forks source link

[koa] Unexpected exit with code 0 during an http request #4

Closed pm0 closed 4 years ago

pm0 commented 4 years ago

Our prod deployment of a koa server is exiting several times a day with little info logged. There is logging on a number of node process events including beforeExit, exit, close, uncaughtExceptionMonitor and unhandledRejection but only exit is triggered. None of our code calls exit() explicitly and looking through npm packages we use it doesn't look like any of them would be calling it either.

The exit happens during a request to a specific API PUT endpoint where the body payload is relatively large compared to other calls, but not huge (around 15-30KB). It's not happening consistently on every request, as a server restart and re-attempt with the same data can work in most cases.

Based on log timestamps the exit happens immediately when the request is made. Any exception around these calls would be handled and logged but it looks like no exception is thrown. This issue has happened when our codebase used the co-request library to manage http requests as well as after migrating to axios.

My understanding is that node will exit when there are no pending async operations, which could indicate koa is stopping for some reason?

jonathanong commented 4 years ago

this isn't koa. i've seen this before and it's usually from errors thrown improperly async. native modules/functions require() have been a big culprit for me

pm0 commented 4 years ago

@jonathanong thanks for the info, can you elaborate what you mean by errors thrown improperly async? Is it likely to be an uncaught exception or something else killing the process?

jonathanong commented 4 years ago

yeah, the last instance i remember was when a require() threw inside an async function

pm0 commented 4 years ago

The exit was not caused by an exception but an explicit call to process.exit in an xml validator library. Not exactly sure of the cause but it seems related to this issue https://github.com/meteor/meteor/issues/7012 (though we aren't using Meteor).