So acquired is always true, and the listener is always attached. release() then early-returns for the same unset limit, which makes both the closure and the listener pure overhead for that app.
Why it matters
maxConcurrentRequests is opt-in and defaults to unlimited, so the overwhelming majority of apps pay this and get nothing back. It is a closure allocation and an EventEmitter registration per request, on the hot path, for a feature that is off.
Small in absolute terms. Filed because the pipeline-context work already established that per-request allocations here are worth watching, and because the fix is trivial enough that leaving it undone is a choice rather than a tradeoff.
Scope
Hoist a boolean when the handler is built and guard both the listener and the acquire bookkeeping with it:
Then the gate does nothing at all — no listener, no flag — for an app that never configured it. Worth checking whether createRequestGate should expose that instead of having the caller re-derive it from opts.
Related
Found reviewing Expressive-Tea/green-tea#23 on GitHub. Deliberately let through so the PR could land: the two findings that mattered (a permanent slot leak, and a 503 that was the only non-JSON error in the tree) were fixed, and this one affects nothing. Taking it here rather than sending the contributor round a fourth time.
The request gate registers a `close` listener on every request, including in apps that never set `maxConcurrentRequests`.
## What happens
`src/http/server.ts`, in the per-request handler:
```ts
if (!gate.acquire()) { /* 503 */ }
acquired = true;
res.once('close', () => {
if (!acquired) return;
acquired = false;
gate.release();
});
```
`acquire()` returns `true` unconditionally when the limit is unset:
```ts
acquire(): boolean {
if (limit === undefined || limit <= 0) return true;
...
}
```
So `acquired` is always `true`, and the listener is always attached. `release()` then early-returns for the same unset limit, which makes both the closure and the listener pure overhead for that app.
## Why it matters
`maxConcurrentRequests` is opt-in and defaults to unlimited, so the overwhelming majority of apps pay this and get nothing back. It is a closure allocation and an `EventEmitter` registration per request, on the hot path, for a feature that is off.
Small in absolute terms. Filed because the pipeline-context work already established that per-request allocations here are worth watching, and because the fix is trivial enough that leaving it undone is a choice rather than a tradeoff.
## Scope
Hoist a boolean when the handler is built and guard both the listener and the acquire bookkeeping with it:
```ts
const limited = (opts?.limits?.maxConcurrentRequests ?? 0) > 0;
```
Then the gate does nothing at all — no listener, no flag — for an app that never configured it. Worth checking whether `createRequestGate` should expose that instead of having the caller re-derive it from `opts`.
## Related
Found reviewing Expressive-Tea/green-tea#23 on GitHub. Deliberately let through so the PR could land: the two findings that mattered (a permanent slot leak, and a 503 that was the only non-JSON error in the tree) were fixed, and this one affects nothing. Taking it here rather than sending the contributor round a fourth time.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
The request gate registers a
closelistener on every request, including in apps that never setmaxConcurrentRequests.What happens
src/http/server.ts, in the per-request handler:acquire()returnstrueunconditionally when the limit is unset:So
acquiredis alwaystrue, and the listener is always attached.release()then early-returns for the same unset limit, which makes both the closure and the listener pure overhead for that app.Why it matters
maxConcurrentRequestsis opt-in and defaults to unlimited, so the overwhelming majority of apps pay this and get nothing back. It is a closure allocation and anEventEmitterregistration per request, on the hot path, for a feature that is off.Small in absolute terms. Filed because the pipeline-context work already established that per-request allocations here are worth watching, and because the fix is trivial enough that leaving it undone is a choice rather than a tradeoff.
Scope
Hoist a boolean when the handler is built and guard both the listener and the acquire bookkeeping with it:
Then the gate does nothing at all — no listener, no flag — for an app that never configured it. Worth checking whether
createRequestGateshould expose that instead of having the caller re-derive it fromopts.Related
Found reviewing Expressive-Tea/green-tea#23 on GitHub. Deliberately let through so the PR could land: the two findings that mattered (a permanent slot leak, and a 503 that was the only non-JSON error in the tree) were fixed, and this one affects nothing. Taking it here rather than sending the contributor round a fourth time.