node-server icon indicating copy to clipboard operation
node-server copied to clipboard

Version ^1.18.0 produces empty response

Open mjeanroy opened this issue 4 months ago • 1 comments

Hi 👋 ,

I recently upgraded from version ^1.17.1 to version ^1.18.0 (reproduced with 1.18.0 and 1.18.2) and I discovered a regression that produces empty response.

For the context, I'm using @hono/node-server on AWS ECS (with the node:22-alpine docker image) behind Cloudfront, and here is what happening:

  • My application produces a JSON response, everything is ok at this point, I can log the response before it is processed by @hono/node-server and everything seems ok.
  • Problem: when the browser receives the response, the response body is empty:
    • Content-Length is set to zero.
    • I don't receive any bytes.

I think it is likely due to this PR.

I tried to dig a bit the change in this PR, and I think that the following is happening:

  • The content-length is computed and set to the resHeaderRecord object.
  • Then, collected chunk values are written to the response:
    • (outgoing as Writable).write(value) is called for all chunks
    • Then outgoing.end() is called

What I suspect:

Option 1:

In some cases, outgoing.end() is called before the write operation is completed. The current code does not check if we need to wait for the drain signal, which could be the reason but I'm not sure of course.

In this case, Cloudfront receives a truncated response (with a Content-Length header that does not match the actual response size) and chose to return an empty response with a Content-Length to zero.

Option 2:

The read promise is not resolved after the three attempts, so the Content-Length header is never set.

In this case, Cloudfront see that there is no Content-Length, so there is nothing to return and returns an empty response to the browser.

Of course, I'm far from being sure if one these two analysis is correct, but I can reproduce it quite easily with "big response body" (it almost never happen if the response body is "small").

Happy to help since I can reproduce quite easily on my side.

As a temporary fix, I downgraded to @hono/[email protected] and everything works like a charm.

mjeanroy avatar Aug 13 '25 20:08 mjeanroy

Hi @mjeanroy,

Thanks for the report. Apologies for the delayed response. Would you be able to share the code or project that reproduces the problematic behavior?

usualoma avatar Sep 07 '25 05:09 usualoma