QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.46k stars 1.26k forks source link

[🐞] Stream of `server$` response is randomly destroyed while the page reloading. #5028

Closed genki closed 2 months ago

genki commented 10 months ago

Which component is affected?

Qwik City (routing)

Describe the bug

When I am developing, HMR causes error randomly on the dev server like this:

Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed
    at new NodeError (node:internal/errors:405:5)
    at Http2ServerResponse.write (node:internal/http2/compat:736:13)
    ...

This is happening when the running server$ response has been interrupted by the page reloading. I think this is not the error must be logged because such the stream abortion by the browser is usual situation. How about to remove this console.error()? https://github.com/BuilderIO/qwik/blob/925389b418a58eecc43620251d8268b8084b5325/packages/qwik-city/middleware/node/http.ts#L99-L103

Reproduction

not supplied

Steps to reproduce

This issue can happen oftenly in situation that the server checking the exit of page by calling server$ function at the event of window.onbeforeunload.

System Info

System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M2
    Memory: 76.30 MB / 24.00 GB
    Shell: 3.6.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.5.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - /opt/homebrew/bin/npm
    pnpm: 8.6.11 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 116.0.5845.110
    Safari: 16.5.2
  npmPackages:
    @builder.io/partytown: ^0.8.0 => 0.8.0 
    undici: 5.22.1 => 5.22.1 
    vite: 4.4.7 => 4.4.7

Additional Information

No response

genki commented 10 months ago

If there is an option to use the navigator.sendBeacon() instead of the fetch() for server$, it may solve the issue.

mhevery commented 10 months ago

We will need a reproduction; otherwise, we can't do much with this issue...

genki commented 10 months ago

@mhevery I have tried to make it, but for now another issue blocks it. Currently the server$ function is not callable in the useVisibleTask$

https://stackblitz.com/edit/qwik-starter-slbpcn?file=src%2Froutes%2Findex.tsx

I will retry after this will be solved.

genki commented 10 months ago

It says out2Clone.tee is not a function or its return value is not iterable It seemed that using undefined function in browsers among the server$

genki commented 10 months ago

Ah, the same issue has been reported #5044 It may need to wait the stackblitz upgrades its node version.

PatrickJS commented 2 months ago

mhevery I have tried to make it, but for now another issue blocks it. Currently the server$ function is not callable in the useVisibleTask$

stackblitz.com/edit/qwik-starter-slbpcn?file=src%2Froutes%2Findex.tsx

I will retry after this will be solved.

this works https://stackblitz.com/edit/qwik-starter-rvzkyr?file=src%2Froutes%2Findex.tsx

I'll make a pr to ignore ERR_HTTP2_INVALID_STREAM errors