fix(response): make send() a no-op when response already finished (#134)#135
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The fix is straightforward but I think we don't need explicit e2e particularly to test this. E2E tests are not something we simply test for a branch or a smaller change but it decides a whole feature. If you have to add tests then add unit tests to test this branch/functionality. Hope it makes sense. |
Fixes FOSSFORGE#134 UwsResponse.send() threw 'Response already sent' when called on an already-finished response. This occurred during NestJS's normal exception-filter flow: when a handler sends a response then throws, NestJS calls adapter.end(response) for graceful cleanup, which delegated to send() and triggered the throw. The throw bubbled into RouteRegistry.handleException() and was logged as a spurious 'Unhandled route error' stack trace, even though the client had already received their response successfully. Changed the guard from a throw to a silent return, matching the behavior of Express and Fastify. Updated existing unit test in response.spec.ts to assert the new no-op behavior (verifies end() is called exactly once, not twice).
174d6f6 to
2b92d33
Compare
|
Updated — replaced the e2e test with a unit test in src/http/core/response.spec.ts. There was already a test asserting the old throwing behavior; I flipped it to assert the no-op (also verifies end() is called exactly once). All 133 unit tests pass. |
Fixes #134.
When a handler sends a response then throws, NestJS's exception filter calls
adapter.end(response)to gracefully close the response. This delegated toUwsResponse.send(), which threwError: Response already sentbecausethis.finishedwas alreadytrue. The throw was logged as a spurious "Unhandled route error" even though the client had already received their response.Change
In
src/http/core/response.ts, changed the guard from a throw to a silent return — matching Express and Fastify behavior:Testing
Added
test/http/response-send-after-finished.e2e.spec.tswith two tests:send()Both pass. Pre-existing failures in
static-file-serving.e2e.spec.tswere observed on cleanmainand are unrelated to this change.Summary by CodeRabbit
Bug Fixes