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: cleanup signal listener #1113

Merged
merged 2 commits into from
Dec 13, 2021
Merged

fix: cleanup signal listener #1113

merged 2 commits into from
Dec 13, 2021

Conversation

ronag
Copy link
Member

@ronag ronag commented Nov 27, 2021

No description provided.

@ronag ronag requested a review from benjamingr November 27, 2021 17:48
@ronag ronag force-pushed the weak-signal-forward branch from d30fb47 to dbcc205 Compare November 27, 2021 17:48
@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2021

Codecov Report

Merging #1113 (6d739f8) into main (caf9ec3) will increase coverage by 0.16%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1113      +/-   ##
==========================================
+ Coverage   94.40%   94.56%   +0.16%     
==========================================
  Files          39       40       +1     
  Lines        3806     3955     +149     
==========================================
+ Hits         3593     3740     +147     
- Misses        213      215       +2     
Impacted Files Coverage Δ
lib/fetch/request.js 81.51% <80.00%> (-0.19%) ⬇️
lib/balanced-pool.js 96.25% <0.00%> (-0.18%) ⬇️
lib/pool.js 100.00% <0.00%> (ø)
lib/pool-base.js 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update caf9ec3...6d739f8. Read the comment docs.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you please add a unit test?

lib/fetch/request.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@ronag
Copy link
Member Author

ronag commented Nov 28, 2021

@benjamingr @dominic not the prettiest solution... any suggestions? The spec doesn't specify how and when the abort listener should be cleaned up.

@benjamingr
Copy link
Member

Remove the abort listener when you know you are not going to abort (when the request finishes, was aborted, errored etc).

FinalizationRegistry is a really heavy handed tool for this

)
const abort = () => ac.abort()
signal.addEventListener('abort', abort, { once: true })
requestFinalizer.register(this, { signal, abort })
Copy link
Member

Choose a reason for hiding this comment

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

We should be unregistering this after successful completion. Always passing through the registry is expensive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, but if we could do that we wouldn't need this hack at all.

@ronag
Copy link
Member Author

ronag commented Nov 29, 2021

Remove the abort listener when you know you are not going to abort (when the request finishes, was aborted, errored etc).

It's a little more complicated 😄. The spec doesn't have any request finalisation so I would have to make up something myself.

@benjamingr
Copy link
Member

Oh that's a DOM fetch request? Yeah, I think cheating is probably fine the browser cheats by doing this internally

@ronag ronag force-pushed the main branch 2 times, most recently from 63eab1d to 47eb207 Compare December 12, 2021 12:27
@ronag ronag force-pushed the weak-signal-forward branch from 82e1a51 to 6d739f8 Compare December 13, 2021 14:52
@ronag ronag merged commit 73fb726 into main Dec 13, 2021
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
* fix: cleanup signal listener

* Update lib/fetch/request.js
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* fix: cleanup signal listener

* Update lib/fetch/request.js
@Uzlopak Uzlopak deleted the weak-signal-forward branch February 21, 2024 12:37
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fix: cleanup signal listener

* Update lib/fetch/request.js
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.

4 participants