@nxtedition/lib 26.3.3 → 26.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/http.js +21 -9
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -199,10 +199,14 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export async function requestMiddleware(ctx, next) {
|
|
202
|
-
const { req, res, target } = ctx
|
|
202
|
+
const { req, res, target, stats } = ctx
|
|
203
203
|
const startTime = performance.now()
|
|
204
204
|
|
|
205
205
|
const reqLogger = ctx.logger?.child({ req })
|
|
206
|
+
|
|
207
|
+
if (stats?.pending != null) {
|
|
208
|
+
stats.pending++
|
|
209
|
+
}
|
|
206
210
|
try {
|
|
207
211
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
208
212
|
if (!isHealthcheck) {
|
|
@@ -235,14 +239,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
235
239
|
|
|
236
240
|
const thenable = next()
|
|
237
241
|
|
|
238
|
-
if (!req.destroyed || req.errored) {
|
|
239
|
-
req.on('error', noop)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (!res.destroyed || res.errored) {
|
|
243
|
-
res.on('error', noop)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
242
|
if (thenable?.then) {
|
|
247
243
|
await thenable
|
|
248
244
|
}
|
|
@@ -269,6 +265,18 @@ export async function requestMiddleware(ctx, next) {
|
|
|
269
265
|
} catch (err) {
|
|
270
266
|
ctx[kAbortController]?.abort(err)
|
|
271
267
|
|
|
268
|
+
if (!req.closed) {
|
|
269
|
+
req.on('error', (err) => {
|
|
270
|
+
reqLogger?.warn({ err }, 'request error')
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!res.closed) {
|
|
275
|
+
res.on('error', (err) => {
|
|
276
|
+
reqLogger?.warn({ err }, 'response error')
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
|
|
272
280
|
const statusCode = err.statusCode || err.$metadata?.httpStatusCode || 500
|
|
273
281
|
const elapsedTime = performance.now() - startTime
|
|
274
282
|
|
|
@@ -334,6 +342,10 @@ export async function requestMiddleware(ctx, next) {
|
|
|
334
342
|
res.destroy(err)
|
|
335
343
|
}
|
|
336
344
|
} finally {
|
|
345
|
+
if (stats?.pending != null) {
|
|
346
|
+
stats.pending--
|
|
347
|
+
}
|
|
348
|
+
|
|
337
349
|
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
338
350
|
// Do nothing..
|
|
339
351
|
} else {
|