maxConcurrentRequests sheds a request with a request:end and no request:start — the first pair the stream breaks #73

Closed
opened 2026-08-30 17:45:40 +00:00 by chrnx · 0 comments
Owner

Every terminal path in the tree today emits request:start and request:end as a pair. Expressive-Tea/green-tea#23 adds the first one that does not.

What happens

On contrib at 4b04421, one subscriber on each event, five shapes of request:

Request HTTP request:start request:end
matched handler 200 1 1
unmatched route 404 1 1
handler throws 500 1 1
body over maxBodyBytes 413 1 1
CORS preflight 204 1 1

Both come from observedDispatch (src/http/core.ts:245 and :259), each behind its own hasListeners guard, so a subscriber to both always sees both.

With #23 applied, the shed request:

Request HTTP request:start request:end
over maxConcurrentRequests 503 0 1

It never reaches handle() — the gate returns above it — and the adapter emits request:end on its own.

Why it matters

Not that #23 is wrong. request:end is the only event carrying a real status, so a shed request that emitted nothing would be worse: the operator loses exactly the number they want under saturation, which is why the event was asked for in review.

The problem is that nothing says whether the pairing is a guarantee. LifecycleEvent does not document it, the README does not, and until now the code has upheld it by accident of having a single emitter. A consumer that opens per-requestId state on request:start and closes it on request:end works against every version shipped so far, and starts leaking half-open entries the first time a server sheds — under load, which is when it can least afford them.

Scope

Pick one and write it down:

  • The pair is guaranteed. Then #23 emits a request:start before the shed request:end, and so does every future emitter.
  • It is not. Then request:end is documented as standalone-terminal, and consumers are told to key off it alone.

Either is fine. The one that is not fine is leaving a reader to infer it from src/http/core.ts.

Adjacent to #64, which asks the same class of question — what does a consumer count — from the other direction. Worth answering both in one pass over the lifecycle docs.

Related

Found while reviewing #23. Not blocking it: the behaviour is defensible either way once it is written down.

Every terminal path in the tree today emits `request:start` and `request:end` as a pair. Expressive-Tea/green-tea#23 adds the first one that does not. ## What happens On `contrib` at 4b04421, one subscriber on each event, five shapes of request: | Request | HTTP | `request:start` | `request:end` | |---|---|---|---| | matched handler | 200 | 1 | 1 | | unmatched route | 404 | 1 | 1 | | handler throws | 500 | 1 | 1 | | body over `maxBodyBytes` | 413 | 1 | 1 | | CORS preflight | 204 | 1 | 1 | Both come from `observedDispatch` (`src/http/core.ts:245` and `:259`), each behind its own `hasListeners` guard, so a subscriber to both always sees both. With #23 applied, the shed request: | Request | HTTP | `request:start` | `request:end` | |---|---|---|---| | over `maxConcurrentRequests` | 503 | **0** | 1 | It never reaches `handle()` — the gate returns above it — and the adapter emits `request:end` on its own. ## Why it matters Not that #23 is wrong. `request:end` is the only event carrying a real `status`, so a shed request that emitted nothing would be worse: the operator loses exactly the number they want under saturation, which is why the event was asked for in review. The problem is that nothing says whether the pairing is a guarantee. `LifecycleEvent` does not document it, the README does not, and until now the code has upheld it by accident of having a single emitter. A consumer that opens per-`requestId` state on `request:start` and closes it on `request:end` works against every version shipped so far, and starts leaking half-open entries the first time a server sheds — under load, which is when it can least afford them. ## Scope Pick one and write it down: - **The pair is guaranteed.** Then #23 emits a `request:start` before the shed `request:end`, and so does every future emitter. - **It is not.** Then `request:end` is documented as standalone-terminal, and consumers are told to key off it alone. Either is fine. The one that is not fine is leaving a reader to infer it from `src/http/core.ts`. Adjacent to #64, which asks the same class of question — what does a consumer count — from the other direction. Worth answering both in one pass over the lifecycle docs. ## Related Found while reviewing #23. Not blocking it: the behaviour is defensible either way once it is written down.
chrnx closed this issue 2026-09-04 13:32:28 +00:00
Sign in to join this conversation.