@nxtedition/lib 26.0.21 → 26.0.22
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 +10 -0
- package/package.json +1 -1
- package/util/template/index-common.js +1 -1
package/http.js
CHANGED
|
@@ -13,6 +13,8 @@ export const kAbortController = Symbol('abortController')
|
|
|
13
13
|
const ERR_HEADER_EXPR =
|
|
14
14
|
/^(content-length|content-type|te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
|
|
15
15
|
|
|
16
|
+
const pending = (globalThis._nxt_lib_http_pending = new Set())
|
|
17
|
+
|
|
16
18
|
// https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
|
|
17
19
|
// 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
|
|
18
20
|
// With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days.
|
|
@@ -145,6 +147,7 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
145
147
|
})
|
|
146
148
|
|
|
147
149
|
const reqLogger = ctx.logger?.child({ req })
|
|
150
|
+
pending.add(ctx)
|
|
148
151
|
try {
|
|
149
152
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
150
153
|
if (!isHealthcheck) {
|
|
@@ -191,6 +194,7 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
191
194
|
}
|
|
192
195
|
socket.destroy(err)
|
|
193
196
|
} finally {
|
|
197
|
+
pending.delete(ctx)
|
|
194
198
|
if (!socket.writableEnded && !socket.destroyed) {
|
|
195
199
|
socket.destroy()
|
|
196
200
|
reqLogger?.warn('socket destroyed')
|
|
@@ -203,6 +207,7 @@ export async function requestMiddleware(ctx, next) {
|
|
|
203
207
|
const startTime = performance.now()
|
|
204
208
|
|
|
205
209
|
const reqLogger = ctx.logger?.child({ req })
|
|
210
|
+
pending.add(ctx)
|
|
206
211
|
try {
|
|
207
212
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
208
213
|
if (!isHealthcheck) {
|
|
@@ -334,6 +339,7 @@ export async function requestMiddleware(ctx, next) {
|
|
|
334
339
|
res.destroy(err)
|
|
335
340
|
}
|
|
336
341
|
} finally {
|
|
342
|
+
pending.delete(ctx)
|
|
337
343
|
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
338
344
|
// Do nothing..
|
|
339
345
|
} else {
|
|
@@ -728,6 +734,7 @@ export async function request(ctx, next) {
|
|
|
728
734
|
|
|
729
735
|
let reqLogger = logger
|
|
730
736
|
|
|
737
|
+
pending.add(ctx)
|
|
731
738
|
try {
|
|
732
739
|
ctx.url = requestTarget(req)
|
|
733
740
|
if (!ctx.url) {
|
|
@@ -837,6 +844,7 @@ export async function request(ctx, next) {
|
|
|
837
844
|
}
|
|
838
845
|
}
|
|
839
846
|
} finally {
|
|
847
|
+
pending.delete(ctx)
|
|
840
848
|
if (!res.writableEnded) {
|
|
841
849
|
res.destroy()
|
|
842
850
|
logger.debug('request destroyed')
|
|
@@ -914,6 +922,7 @@ export async function upgrade(ctx, next) {
|
|
|
914
922
|
|
|
915
923
|
let aborted = false
|
|
916
924
|
let reqLogger = logger
|
|
925
|
+
pending.add(ctx)
|
|
917
926
|
try {
|
|
918
927
|
ctx.url = requestTarget(req)
|
|
919
928
|
if (!ctx.url) {
|
|
@@ -978,6 +987,7 @@ export async function upgrade(ctx, next) {
|
|
|
978
987
|
|
|
979
988
|
socket.destroy(err)
|
|
980
989
|
} finally {
|
|
990
|
+
pending.delete(ctx)
|
|
981
991
|
queueMicrotask(() => ac.abort())
|
|
982
992
|
}
|
|
983
993
|
}
|
package/package.json
CHANGED
|
@@ -209,7 +209,7 @@ export function makeTemplateCompiler({ ds, proxify, logger, platform }) {
|
|
|
209
209
|
return resolver ? (args$) => resolver(template, args$) : null
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
function resolveTemplate(template, args$, options) {
|
|
212
|
+
async function resolveTemplate(template, args$, options) {
|
|
213
213
|
const expr = _compileTemplate(template)
|
|
214
214
|
return expr ? firstValueFrom(expr(template, args$), options) : template
|
|
215
215
|
}
|