Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@netlify/remix-edge-adapter): don't close the stream twice #444

Merged
merged 3 commits into from
Sep 5, 2024

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Sep 4, 2024

Description

Fixes TypeError: Closed already requested that started to be thrown with deno@1.43.0. Suspected underlying reason for change is denoland/deno#23425 and now we receive abort signal after all the work was already completed and response stream is being attempted to close twice (?).

TBF, this feels weird that ReactDOMServer.renderToReadableStream doesn't handle this in some way to prevent closing stream multiple times. I needed to do tricks with identity TransformStream to figure out state of the stream and prevent signal from resulting in the error.

Alternatives to current fix are those (one of them):

Edit:
There is also another error happening (or have been happening):

ReadableByteStreamController's stream is not in a readable state

Which I can't reproduce and also am not seeing it in logs for currently deployed demo site, it's unclear to me wether they are related or not (other than this is can thrown also when attempting to close the stream - https://github.com/denoland/deno/blob/b01578ae1fc1da65ac38daec31a23c9ef652aa74/ext/web/06_streams.js#L5845-L5857 )

Related Tickets & Documents

  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Compare logs from:

There are no error logs produced anymore for each request

For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This
    ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a
    typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style
    guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

Copy link

netlify bot commented Sep 4, 2024

Deploy Preview for remix-edge ready!

Name Link
🔨 Latest commit 4f5d760
🔍 Latest deploy log https://app.netlify.com/sites/remix-edge/deploys/66d9f6c937a5e10008c43e5c
😎 Deploy Preview https://deploy-preview-444--remix-edge.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Sep 4, 2024

Deploy Preview for remix-serverless ready!

Name Link
🔨 Latest commit 4f5d760
🔍 Latest deploy log https://app.netlify.com/sites/remix-serverless/deploys/66d9f6c91b08ab00081b2600
😎 Deploy Preview https://deploy-preview-444--remix-serverless.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Sep 4, 2024
@pieh pieh force-pushed the dont-close-stream-twice branch from f91f65b to a6fb43a Compare September 5, 2024 09:31
@pieh pieh force-pushed the dont-close-stream-twice branch from a6fb43a to f953478 Compare September 5, 2024 09:42
@pieh pieh marked this pull request as ready for review September 5, 2024 09:59
@pieh pieh requested a review from a team as a code owner September 5, 2024 09:59
@pieh pieh changed the title fix: don't close the stream twice fix(@netlify/remix-edge-adapter): don't close the stream twice Sep 5, 2024
Copy link

@orinokai orinokai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you say, it's odd that this isn't handled in some way by React - but this solution preserves the handling of abort and doesn't introduce much complexity, so lgtm

Copy link
Contributor

@serhalp serhalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing!

@pieh pieh enabled auto-merge (squash) September 5, 2024 18:22
@pieh pieh merged commit 07bef21 into main Sep 5, 2024
15 checks passed
@pieh pieh deleted the dont-close-stream-twice branch September 5, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants