1
0
mirror of synced 2025-12-20 02:19:14 -05:00

Add timeout and abort middleware and processing halts (#18177)

* Add middleware to timeout requests after a period

* Add halt-on-dropped-connection middleware to stop the middleware processing stack if the connection was already dropped

* Add a few strategic bail-out spots for dropped connections during the render-page middleware

* Handle 404s and HEAD requests earlier in the page rendering flow

* Add a few more strategic bail-out spots for dropped connections during the render-page middleware

* Add middleware to notice aborted requests

* Add a check for aborted requests into the isConnectionDropped logic

* Reformat comment for consistency

* Handle aborted requests correctly in the error handler

* Explicit returns for consistency
This commit is contained in:
James M. Greene
2021-03-09 13:14:02 -06:00
committed by GitHub
parent 1ee4d3f670
commit fd7d0eeb1a
8 changed files with 126 additions and 29 deletions

View File

@@ -6,7 +6,9 @@ const loadSiteData = require('../lib/site-data')
function shouldLogException (error) {
const IGNORED_ERRORS = [
// avoid sending CSRF token errors (from bad-actor POST requests)
'EBADCSRFTOKEN'
'EBADCSRFTOKEN',
// Client connected aborted
'ECONNRESET'
]
if (IGNORED_ERRORS.includes(error.code)) {
@@ -26,8 +28,8 @@ async function logException (error, req) {
}
module.exports = async function handleError (error, req, res, next) {
// If the headers have already been sent...
if (res.headersSent) {
// If the headers have already been sent or the request was aborted...
if (res.headersSent || req.aborted) {
// Report to Failbot
await logException(error, req)