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

Stop flowing and then abort if a stream is cancelled #27405

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

sebmarkbage
Copy link
Collaborator

We currently abort a stream either it's explicitly told to abort (e.g. by an abortsignal). In this case we still finish writing what we have as well as instructions for the client about what happened so it can trigger fallback cases and log appropriately.

We also abort a request if the stream itself cancels. E.g. if you can't write anymore. In this case we should not write anything to the outgoing stream since it's supposed to be closed already now. However, we should still abort the request so that more work isn't performed and so that we can log the reason for it to the onError callback.

We should also not do any work after aborting.

There we need to stop the "flow" of bytes - so I call stopFlowing in the cancel case before aborting.

The tests were testing this case but we had changed the implementation to only start flowing at initial read (pull) instead of start like we used to. As a result, it was no longer covering this case. We have to call reader.read() in the tests to start the flow so that we need to cancel it.

We also were missing a final assertion on the error logs and since we were tracking them explicitly the extra error was silenced.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Sep 22, 2023
@@ -78,7 +79,10 @@ function renderToReadableStream(
pull: (controller): ?Promise<void> => {
startFlowing(request, controller);
},
cancel: (reason): ?Promise<void> => {},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In Flight we weren't even cancelling it at all in this case.

@react-sizebot
Copy link

react-sizebot commented Sep 22, 2023

Comparing: 56b1447...89b4b50

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 = 166.66 kB 166.66 kB = 52.14 kB 52.14 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 176.10 kB 176.10 kB = 54.98 kB 54.97 kB
facebook-www/ReactDOM-prod.classic.js = 571.96 kB 571.96 kB = 100.66 kB 100.66 kB
facebook-www/ReactDOM-prod.modern.js = 555.68 kB 555.68 kB = 97.77 kB 97.77 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-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0.83% 27.74 kB 27.97 kB +0.71% 9.43 kB 9.49 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0.83% 27.74 kB 27.97 kB +0.71% 9.43 kB 9.49 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.81% 28.27 kB 28.50 kB +0.69% 9.59 kB 9.65 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.81% 28.27 kB 28.50 kB +0.69% 9.59 kB 9.65 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0.79% 28.90 kB 29.13 kB +0.68% 9.72 kB 9.78 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.78% 29.43 kB 29.66 kB +0.69% 9.88 kB 9.95 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.50% 106.33 kB 106.86 kB +0.37% 25.37 kB 25.47 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.50% 106.33 kB 106.86 kB +0.37% 25.37 kB 25.47 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.49% 108.38 kB 108.91 kB +0.43% 25.99 kB 26.11 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.49% 108.38 kB 108.91 kB +0.43% 25.99 kB 26.11 kB
oss-stable-semver/react-server/cjs/react-server-flight.production.min.js +0.48% 16.43 kB 16.50 kB +0.20% 5.92 kB 5.93 kB
oss-stable/react-server/cjs/react-server-flight.production.min.js +0.48% 16.43 kB 16.50 kB +0.20% 5.92 kB 5.93 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.48% 110.75 kB 111.28 kB +0.38% 26.13 kB 26.23 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.47% 112.79 kB 113.32 kB +0.43% 26.73 kB 26.84 kB
oss-experimental/react-server/cjs/react-server-flight.production.min.js +0.45% 17.56 kB 17.63 kB +0.24% 6.20 kB 6.21 kB
oss-stable-semver/react-server/cjs/react-server-flight.development.js +0.22% 64.88 kB 65.02 kB +0.17% 15.84 kB 15.87 kB
oss-stable/react-server/cjs/react-server-flight.development.js +0.22% 64.88 kB 65.02 kB +0.17% 15.84 kB 15.87 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +0.21% 69.06 kB 69.21 kB +0.16% 16.47 kB 16.50 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.20% 26.47 kB 26.52 kB +0.17% 8.97 kB 8.99 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.20% 26.47 kB 26.52 kB +0.17% 8.97 kB 8.99 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +0.20% 26.78 kB 26.84 kB +0.14% 9.08 kB 9.10 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +0.20% 26.78 kB 26.84 kB +0.14% 9.08 kB 9.10 kB

Generated by 🚫 dangerJS against 89b4b50

…rrors

Otherwise this will be a lingering task which means we might try to abort
it when we close which would log an extra error but we've already errored.
@sebmarkbage sebmarkbage merged commit d9e00f7 into facebook:main Sep 22, 2023
2 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 22, 2023
We currently abort a stream either it's explicitly told to abort (e.g.
by an abortsignal). In this case we still finish writing what we have as
well as instructions for the client about what happened so it can
trigger fallback cases and log appropriately.

We also abort a request if the stream itself cancels. E.g. if you can't
write anymore. In this case we should not write anything to the outgoing
stream since it's supposed to be closed already now. However, we should
still abort the request so that more work isn't performed and so that we
can log the reason for it to the onError callback.

We should also not do any work after aborting.

There we need to stop the "flow" of bytes - so I call stopFlowing in the
cancel case before aborting.

The tests were testing this case but we had changed the implementation
to only start flowing at initial read (pull) instead of start like we
used to. As a result, it was no longer covering this case. We have to
call reader.read() in the tests to start the flow so that we need to
cancel it.

We also were missing a final assertion on the error logs and since we
were tracking them explicitly the extra error was silenced.

DiffTrain build for [d9e00f7](d9e00f7)
@fivaz
Copy link

fivaz commented Sep 23, 2023

when are you guys publishing the newer release ? I have this problem right now in my nextjs app whenever I refresh my app twice on the browser

EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
We currently abort a stream either it's explicitly told to abort (e.g.
by an abortsignal). In this case we still finish writing what we have as
well as instructions for the client about what happened so it can
trigger fallback cases and log appropriately.

We also abort a request if the stream itself cancels. E.g. if you can't
write anymore. In this case we should not write anything to the outgoing
stream since it's supposed to be closed already now. However, we should
still abort the request so that more work isn't performed and so that we
can log the reason for it to the onError callback.

We should also not do any work after aborting.

There we need to stop the "flow" of bytes - so I call stopFlowing in the
cancel case before aborting.

The tests were testing this case but we had changed the implementation
to only start flowing at initial read (pull) instead of start like we
used to. As a result, it was no longer covering this case. We have to
call reader.read() in the tests to start the flow so that we need to
cancel it.

We also were missing a final assertion on the error logs and since we
were tracking them explicitly the extra error was silenced.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
We currently abort a stream either it's explicitly told to abort (e.g.
by an abortsignal). In this case we still finish writing what we have as
well as instructions for the client about what happened so it can
trigger fallback cases and log appropriately.

We also abort a request if the stream itself cancels. E.g. if you can't
write anymore. In this case we should not write anything to the outgoing
stream since it's supposed to be closed already now. However, we should
still abort the request so that more work isn't performed and so that we
can log the reason for it to the onError callback.

We should also not do any work after aborting.

There we need to stop the "flow" of bytes - so I call stopFlowing in the
cancel case before aborting.

The tests were testing this case but we had changed the implementation
to only start flowing at initial read (pull) instead of start like we
used to. As a result, it was no longer covering this case. We have to
call reader.read() in the tests to start the flow so that we need to
cancel it.

We also were missing a final assertion on the error logs and since we
were tracking them explicitly the extra error was silenced.

DiffTrain build for commit d9e00f7.
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.

5 participants