Files
sencho/backend
Anso f86042b2ad fix(stack-files): track download metric off the file stream, not the response (#1220)
The download success metric was hung off res.on('finish') with a
res.on('close') fallback for failure. Under the in-process supertest
transport that pair fires in non-deterministic order: in CI the close
event sometimes precedes finish on a clean response, and the recorder
booked the request as an error.

The file stream's lifecycle does NOT race. fs.ReadStream emits:
  - 'end' then 'close' on a clean read,
  - 'close' without 'end' when destroy() runs (the req-close path),
  - 'error' then 'close' on a disk error.

Moving the recorder onto these signals removes the race. The flag still
prevents double-firing when 'close' chases 'end' on success.

Semantic note: success now means "the server finished reading the file
off disk and pushed it into the pipe", which is the strongest signal a
server can produce. Whether the client received the bytes is outside
the server's observable state and was never the actual measurement.
2026-05-25 09:13:51 -04:00
..