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

[Fizz][Float] Do not write after closing the stream #27541

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

gnoff
Copy link
Collaborator

@gnoff gnoff commented Oct 18, 2023

Float methods can hang on to a reference to a Request after the request is closed due to AsyncLocalStorage. If a Float method is called at this point we do not want to attempt to flush anything. This change updates the closing logic to also call stopFlowing which will ensure that any checks against the destination properly reflect that we cannot do any writes. In addition it updates the enqueueFlush logic to existence check the destination inside the work function since it can change across the work scheduling gap if it is async.

fixes: #27540

Float methods can hang on to a reference to a Request after the request is closed due to AsyncLocalStorage. If a Float method is called at this point we do not want to attempt to flush anything. This change updates the closing logic to also call `stopFlowing` which will ensure that any checks against the destination properly reflect that we cannot do any writes. In addition it updates the enqueueFlush logic to existence check the destination inside the work function since it can change across the work scheduling gap if it is async.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 18, 2023
@react-sizebot
Copy link

Comparing: 20c91b6...3b1f90d

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 174.94 kB 174.94 kB = 54.44 kB 54.44 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 177.06 kB 177.06 kB = 55.12 kB 55.12 kB
facebook-www/ReactDOM-prod.classic.js = 567.28 kB 567.28 kB = 99.85 kB 99.85 kB
facebook-www/ReactDOM-prod.modern.js = 551.14 kB 551.14 kB = 96.94 kB 96.94 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-server/cjs/react-server.development.js +0.22% 188.99 kB 189.41 kB +0.32% 44.32 kB 44.46 kB
oss-stable/react-server/cjs/react-server.development.js +0.22% 188.99 kB 189.41 kB +0.32% 44.32 kB 44.46 kB
oss-experimental/react-server/cjs/react-server.development.js +0.21% 199.04 kB 199.47 kB +0.30% 46.16 kB 46.30 kB

Generated by 🚫 dangerJS against 3b1f90d

@gnoff gnoff merged commit 601e5c3 into facebook:main Oct 18, 2023
36 checks passed
@gnoff gnoff deleted the fix-write-after-close branch October 18, 2023 17:05
github-actions bot pushed a commit that referenced this pull request Oct 18, 2023
Float methods can hang on to a reference to a Request after the request
is closed due to AsyncLocalStorage. If a Float method is called at this
point we do not want to attempt to flush anything. This change updates
the closing logic to also call `stopFlowing` which will ensure that any
checks against the destination properly reflect that we cannot do any
writes. In addition it updates the enqueueFlush logic to existence check
the destination inside the work function since it can change across the
work scheduling gap if it is async.

fixes: #27540

DiffTrain build for [601e5c3](601e5c3)
gnoff added a commit that referenced this pull request Oct 18, 2023
In #27541 I added tests to assert
that the write after close bug was fixed. However the Node
implementation has an abort behavior preventing reproduction of the
original issue and the Browser build does not use AsyncLocalStorage
which also prevents reproduction. This change moves the Browser test to
a Edge runtime where AsyncLocalStorage is polyfilled. In this
implementation the test does correctly fail when the patch is removed.
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
Float methods can hang on to a reference to a Request after the request
is closed due to AsyncLocalStorage. If a Float method is called at this
point we do not want to attempt to flush anything. This change updates
the closing logic to also call `stopFlowing` which will ensure that any
checks against the destination properly reflect that we cannot do any
writes. In addition it updates the enqueueFlush logic to existence check
the destination inside the work function since it can change across the
work scheduling gap if it is async.

fixes: facebook#27540
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
In facebook#27541 I added tests to assert
that the write after close bug was fixed. However the Node
implementation has an abort behavior preventing reproduction of the
original issue and the Browser build does not use AsyncLocalStorage
which also prevents reproduction. This change moves the Browser test to
a Edge runtime where AsyncLocalStorage is polyfilled. In this
implementation the test does correctly fail when the patch is removed.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
Float methods can hang on to a reference to a Request after the request
is closed due to AsyncLocalStorage. If a Float method is called at this
point we do not want to attempt to flush anything. This change updates
the closing logic to also call `stopFlowing` which will ensure that any
checks against the destination properly reflect that we cannot do any
writes. In addition it updates the enqueueFlush logic to existence check
the destination inside the work function since it can change across the
work scheduling gap if it is async.

fixes: #27540

DiffTrain build for commit 601e5c3.
@b2whats
Copy link

b2whats commented Jul 16, 2024

Hm, this is not fixed, react version 18.3.1

@eps1lon
Copy link
Collaborator

eps1lon commented Jul 16, 2024

It won't be part of the 18.x release line but React 19. You can try it out in the React release candidate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: ReadableStream can be written to after close
6 participants