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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user