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: don't interact with res if refresh has happened #4370

Merged
merged 3 commits into from Jul 23, 2021

Conversation

danielroe
Copy link
Contributor

Description

In a server context we're getting this error:

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_http_outgoing.js:694:15)
    at ServerResponse.end (_http_outgoing.js:815:7)
    at Timeout._onTimeout (/myproject/node_modules/vite/dist/node/chunks/dep-f2b4ca46.js:66784:21)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

It occurs when making a first SSR request when the vite cache dir is empty.

It seems the issue stems from this timeout getting called and trying to interact with a consumed node response. It seems that it would be possible simply to check whether a response has already been sent before responding.

What is the purpose of this pull request?

  • Bug fix

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@patak-dev
Copy link
Member

Looks like request.writeableEnded was added in v12.9.0. Is there a way to do this work from node v12?

@Shinigami92
Copy link
Member

Looks like request.writeableEnded was added in v12.9.0. Is there a way to do this work from node v12?

I would count v12.9 as v12
I hope no-one needs a pre v12.9 today

@patak-dev
Copy link
Member

We are about to bump the node version to v12.2 with this PR from @sodatea #4279 (comment), we could require v12.9 but this PR then needs to state that in engines and we should queue this one for the next minor, no?

@danielroe
Copy link
Contributor Author

This PR is backwards compatible - behaviour won't change on Node < 12.9. But on 12.9+ it will prevent the error described in the text.

@patak-dev patak-dev merged commit c90b7d9 into vitejs:main Jul 23, 2021
@danielroe danielroe deleted the fix/res-timeout branch July 23, 2021 21:18
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants