-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeout requests and stop processing further #204
Timeout requests and stop processing further #204
Conversation
new RouteTimeoutAbortError( | ||
`Timed out after ${requestTimeoutMs}ms while trying to respond to route ${req.originalUrl}` | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, it would be interesting to attach some more info about the long-running requests that took up all of the time (get the spans).
Future PR stuff though.
Perhaps, it would just be better to have per-request correlated logging and see the other info that way, #9
// We should be able to just `reject(err)` without any special-case handling | ||
// here since ideally, we expect the error to be whatever `signal.reason` we | ||
// aborted with but `child_process.fork(...)` doesn't seem play nicely, see | ||
// https://github.com/nodejs/node/issues/47814 | ||
if (err.name === 'AbortError') { | ||
const childErrorSummary = assembleErrorAfterChildExitsWithErrors( | ||
childExitCode, | ||
childErrors, | ||
childStdErr | ||
); | ||
reject( | ||
new RethrownError( | ||
`Timed out while running ${modulePath} so we aborted the child process after ${timeout}ms. Any child errors? (${childErrors.length})`, | ||
childErrorSummary | ||
) | ||
); | ||
reject(abortController.signal.reason || err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created nodejs/node#47814 to track when we can stop doing this workaround
Timeout requests and stop processing further
Fix #148
Fix #40
async/await
things like requests in the routes so we throw an abort error instead of continuing on. Fix Cancellable requests #40fetch
in Node.js vsnode-fetch
. This gives us the customsignal.reason
that we aborted with instead of a genericAbortError
.fetch
which usesundici
under the hood. Settled on some unofficial instrumentation:opentelemetry-instrumentation-fetch-node
Dev notes
Avoid errors like the following where the route function still continued on after we sent a timeout response to the user:
Instead, we are left with these errors logged to the console each time we timeout. It would be best if we could ignore these in an error handler (added as a TODO here)
Update: Switched to custom errors and native
fetch
in Node.js which emit the customsignal.reason
instead of a generic error. So we now get a lovely error like this:Todo
abortSignal
inrenderHydrogenToString(...)
AbortError
(see dev notes for example) which appear in the logs whenever we timeout. We don't need to see these in the logs