Description of the bug
In setResponse (src/adapters/node/request.ts), res.end() is called inside the for loop that streams the response body. When res.write(value) succeeds (returns true), execution falls through to res.end(), terminating the response after the first chunk. Any response larger than 16KB is silently truncated.
My Observation on the existing code
for (;;) {
const { done, value } = await reader.read();
if (done) break;
if (!res.write(value))
if (process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.LAMBDA_TASK_ROOT)
continue;
else {
res.once("drain", next);
return;
}
res.end(); // called inside the loop after first successful write
}
Expected
res.end() should be placed after the for loop, so the response is only finalized once all chunks have been written.
Reproduction
Use toNodeHandler with any framework (Express, etc.) and serve a route that returns a response larger than 16KB. The response will be truncated at exactly 16,384 bytes.
Issue fixed in pull-request
#124
Description of the bug
In
setResponse(src/adapters/node/request.ts),res.end()is called inside theforloop that streams the response body. Whenres.write(value)succeeds (returnstrue), execution falls through tores.end(), terminating the response after the first chunk. Any response larger than 16KB is silently truncated.My Observation on the existing code
Expected
res.end()should be placed after theforloop, so the response is only finalized once all chunks have been written.Reproduction
Use
toNodeHandlerwith any framework (Express, etc.) and serve a route that returns a response larger than 16KB. The response will be truncated at exactly 16,384 bytes.Issue fixed in pull-request
#124