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: resolve event-loop blocking when aborting a fetch #2660

Closed
wants to merge 1 commit into from

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jan 28, 2024

Resolves #2198

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

Comment on lines +316 to +318
const markResourceTiming = (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2))
? performance.markResourceTiming
: () => {}
Copy link
Contributor Author

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.

Comment on lines +79 to +88
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
Copy link
Contributor Author

@Uzlopak Uzlopak Jan 28, 2024

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))
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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

Copy link
Member

@ronag ronag left a 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?

@Uzlopak Uzlopak mentioned this pull request Jan 29, 2024
7 tasks
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jan 29, 2024

Yes it is an upstream issue.

@Uzlopak Uzlopak closed this Jan 29, 2024
@Uzlopak Uzlopak deleted the fix-event-loop-blocking branch January 29, 2024 03:24
@KhafraDev
Copy link
Member

I don't think this needed to be closed.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jan 29, 2024

Lets discuss this first in the issue. I put the other optimizations into a different PR.

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.

Memory leak when aborting fetch requests
3 participants