-
Notifications
You must be signed in to change notification settings - Fork 772
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
Abort signalling #732
Abort signalling #732
Conversation
🦋 Changeset detectedLatest commit: 89edf75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2091243209/npm-package-wrangler-732 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/732/npm-package-wrangler-732 Or you can use npx https://prerelease-registry.developers.workers.dev/runs/2091243209/npm-package-wrangler-732 dev path/to/script.js |
packages/wrangler/src/proxy.ts
Outdated
@@ -421,6 +427,9 @@ export async function waitForPortToBeAvailable( | |||
} | |||
|
|||
function checkPort() { | |||
// Will clear the interval and timeout if signal is called, | |||
// using resolve prevents Error messages on the console. | |||
options.abortCtrl?.aborted && doResolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's wrap this in a conditional
options.abortCtrl?.aborted && doResolve(); | |
if(options.abortCtrl?.aborted){ | |
doResolve(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably more clear, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @threepointone's suggestions; but otherwise LGTM.
.changeset/wet-tables-pretend.md
Outdated
fix: abort some of the fetches when we unmount the `Remote` component. | ||
Adding abort to the `waitForPortToBeAvailable` as an option and in the `useEffect` the abort signal is called in the return which allows for graceful closing with no hanging | ||
of the `waitForPortToBeAvailable` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: abort some of the fetches when we unmount the `Remote` component. | |
Adding abort to the `waitForPortToBeAvailable` as an option and in the `useEffect` the abort signal is called in the return which allows for graceful closing with no hanging | |
of the `waitForPortToBeAvailable` | |
fix: abort async operations in the `Remote` component to avoid unwanted side-effects | |
When the `Remote` component is unmounted, we now signal outstanding `fetch()` requests, and | |
`waitForPortToBeAvailable()` tasks to cancel them. This prevents unexpected requests from appearing | |
after the component has been unmounted, and also allows the process to exit cleanly without a delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better wording, thank you!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I wonder if the waitForPortToBeAvailable()
abort should be more along the lines of:
export async function waitForPortToBeAvailable(
port: number,
options: { retryPeriod: number; timeout: number; abortCtrl?: AbortSignal }
): Promise<void> {
return new Promise((resolve, reject) => {
abortSignal.onabort(() => {
const abortError = new Error("");
(error as {code: string}).code = "ABORT_ERR";
reject(abortError);
});
89b464c
to
c0eba4c
Compare
packages/wrangler/src/proxy.ts
Outdated
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(options.abortSignal as any).addEventListener("abort", () => { | ||
const error = new Error(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will log "Failed to start server:" which will be confusing to anyone who reads it. Could we add a code or something this error
, and read it on line 307 and not log anything if it's an aborted attempt? Like @petebacondarwin described in #732 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const error = new Error(""); | |
const abortError = new Error("waitForPortToBeAvailable() aborted"); | |
(error as {code: string}).code = "ABORT_ERR"; |
c0eba4c
to
53d0589
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just that one change - otherwise LGTM!
packages/wrangler/src/proxy.ts
Outdated
): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(options.abortSignal as any).addEventListener("abort", () => { | ||
const error = new Error(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const error = new Error(""); | |
const abortError = new Error("waitForPortToBeAvailable() aborted"); | |
(error as {code: string}).code = "ABORT_ERR"; |
…e `useEffect` the abort signal is called in the return which allows for graceful closing with no hanging of the `waitForPortToBeAvailable` fixes #375
53d0589
to
89edf75
Compare
fix: abort async operations in the
Remote
component to avoid unwanted side-effectsWhen the
Remote
component is unmounted, we now signal outstandingfetch()
requests, andwaitForPortToBeAvailable()
tasks to cancel them. This prevents unexpected requests from appearingafter the component has been unmounted, and also allows the process to exit cleanly without a delay.
fixes #375