8000 Node adapter error handling in http stream: throwing async iterable shouldn't result in last HTTP/1.1 chunk being zero-length · Issue #8714 · withastro/astro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Node adapter error handling in http stream: throwing async iterable shouldn't result in last HTTP/1.1 chunk being zero-length #8714
Closed
@mb21

Description

@mb21

Astro Info

Astro                    v3.2.0
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             none

Describe the Bug

It's great that Astro handles JS iterables in its templates and converts them to an HTTP stream, as mentioned in the docs.

However, async iterables can throw/reject, and that case isn't handled very gracefully. (Of course, the 200 status-headers have already been sent, so that's not an option.) The Astro Node adapter only supports HTTP/1.1 (if I understand correctly), so there it's actually fairly clear what to do: simply not terminate with the zero-length end chunk. Because (from marko-js/community#1):

If a chunked response doesn’t terminate with the zero-length end chunk, the client must assume that the response was incomplete — which at the very least, means a cache should double-check with the server before reusing the stored incomplete response.

But Astro currently returns a zero-length chunk.

To reproduce:

---
function * generator () {
  yield 1
  throw Error('ohnoes')
}
---
<body>
  {generator()}
</body>

and run npm run build && npm run preview, then in another terminal curl --raw -i http://localhost:4321. This prints.

HTTP/1.1 200 OK
Transfer-Encoding: chunked
[...]
<body>
1
1
15
Internal server error
0

What's the expected result?

HTTP/1.1 200 OK
Transfer-Encoding: chunked
[...]
<body>
1
1
15
Internal server error

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-v33sgm?file=src%2Fpages%2Findex.astro

(Note that the curl built into stackblitz somehow doesn't have a --raw option, so you need to download the example.)

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: nodeRelated to Node adapter (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0