-
Notifications
You must be signed in to change notification settings - Fork 594
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: resolve event-loop blocking when aborting a fetch #2660
Conversation
const markResourceTiming = (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) | ||
? performance.markResourceTiming | ||
: () => {} |
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 showed hot in the flame graphs, low hanging fruit.
for (const client of this[kClients]) { | ||
if (!client[kNeedDrain]) { | ||
return client | ||
} | ||
} | ||
|
||
if (!this[kConnections] || this[kClients].length < this[kConnections]) { | ||
dispatcher = this[kFactory](this[kUrl], this[kOptions]) | ||
const dispatcher = this[kFactory](this[kUrl], this[kOptions]) | ||
this[kAddClient](dispatcher) | ||
return dispatcher |
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 was also kind of slow while benchmarking. Low hanging fruit
|
||
// https://fetch.spec.whatwg.org/#abort-fetch | ||
function abortFetch (p, request, responseObject, error) { | ||
// 1. Reject promise with error. | ||
p.reject(error) | ||
setImmediate(() => p.reject(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 shouldn't be necessary according to spec. Are we sure this is a spec bug and not something else?
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.
Something is clogging the event loop. As I see other tests fail. So this is not the solution for the issue.
calling setImmediate resulted in declogging it. Still investigating.
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 think this is an issue in v8, I vaguely recall an issue in node core where promises weren't being GC'ed in a loop
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.
@@ -313,16 +313,14 @@ function finalizeAndReportTiming (response, initiatorType = 'other') { | |||
} | |||
|
|||
// https://w3c.github.io/resource-timing/#dfn-mark-resource-timing | |||
function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) { | |||
if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) { | |||
performance.markResourceTiming(timingInfo, originalURL.href, initiatorType, globalThis, cacheState) |
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.
originalURL is being passed instead of the stringified url
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.
maybe leave optimization to separate PR?
Yes it is an upstream issue. |
I don't think this needed to be closed. |
Lets discuss this first in the issue. I put the other optimizations into a different PR. |
Resolves #2198
This relates to...
Rationale
Changes
Features
Bug Fixes
Breaking Changes and Deprecations
Status