Skip to content

Commit cfdb360

Browse files
committed
chore: bump @gravity-ui/nodekit devDependency to ^2.10.1
Required for isEnded() method on AppContext type.
1 parent b394a92 commit cfdb360

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@commitlint/cli": "^17.7.1",
3131
"@commitlint/config-conventional": "^17.7.0",
3232
"@gravity-ui/eslint-config": "^3.2.0",
33-
"@gravity-ui/nodekit": "^2.7.0",
33+
"@gravity-ui/nodekit": "^2.10.1",
3434
"@gravity-ui/prettier-config": "^1.1.0",
3535
"@gravity-ui/tsconfig": "^1.0.0",
3636
"@types/accept-language-parser": "^1.5.6",

src/router.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function isAllowedMethod(method: string): method is Lowercase<HttpMethod> | 'mou
2323
function wrapMiddleware(fn: AppMiddleware, i?: number): AppMiddleware {
2424
const result: AppMiddleware = async (req, res, next) => {
2525
const reqCtx = req.ctx;
26-
if (reqCtx.isEnded()) {
26+
// Skip creating child context if parent is already ended (e.g. client disconnected)
27+
if (reqCtx.abortSignal.aborted) {
2728
return next();
2829
}
2930
const ctx = reqCtx.create(`${fn.name || `noname-${i}`} middleware`);
@@ -57,7 +58,8 @@ function wrapRouteHandler(fn: AppRouteHandler, handlerName?: string) {
5758
const handlerNameLocal = handlerName || fn.name || UNNAMED_CONTROLLER;
5859

5960
const handler: AppMiddleware = async (req, res, next) => {
60-
if (req.originalContext.isEnded()) {
61+
// Skip creating child context if parent is already ended (e.g. client disconnected)
62+
if (req.originalContext.abortSignal.aborted) {
6163
return;
6264
}
6365
req.ctx = req.originalContext.create(handlerNameLocal);

src/tests/context-lifecycle.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,9 @@ describe('Context Lifecycle', () => {
328328
});
329329

330330
describe('Client Disconnect Handling', () => {
331-
it('should not throw when middleware runs after client disconnect', async () => {
331+
it('should skip next middleware when context is already ended', async () => {
332332
let slowMiddlewareCalled = false;
333+
let nextMiddlewareCalled = false;
333334

334335
const slowMiddleware = async (req: Request, _res: Response, next: NextFunction) => {
335336
slowMiddlewareCalled = true;
@@ -342,10 +343,15 @@ describe('Context Lifecycle', () => {
342343
next();
343344
};
344345

346+
const nextMiddleware = (_req: Request, _res: Response, next: NextFunction) => {
347+
nextMiddlewareCalled = true;
348+
next();
349+
};
350+
345351
const nodekit = new NodeKit();
346352
const app = new ExpressKit(nodekit, {
347353
'GET /test': {
348-
beforeAuth: [slowMiddleware],
354+
beforeAuth: [slowMiddleware, nextMiddleware],
349355
handler: (_req: Request, res: Response) => {
350356
res.json({ok: true});
351357
},
@@ -358,6 +364,7 @@ describe('Context Lifecycle', () => {
358364
.catch(() => {});
359365

360366
expect(slowMiddlewareCalled).toBe(true);
367+
expect(nextMiddlewareCalled).toBe(false);
361368
});
362369

363370
it('should not throw when route handler runs after client disconnect', async () => {

0 commit comments

Comments
 (0)