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(fetch): listener leaks on Socket #32956

Merged
merged 6 commits into from
Oct 7, 2024
Merged

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Oct 4, 2024

Closes #32951

node:http reuses TCP Sockets under the hood. We weren't cleaning up our listeners, leading to the MaxListenersExceededWarning.

This PR adds cleanup logic. It also raises the warning threshhold, so that it doesn't trigger until there's 100 concurrent requests over the same socket.

@Skn0tt Skn0tt requested a review from mxschmitt October 4, 2024 12:15
@Skn0tt Skn0tt self-assigned this Oct 4, 2024
@Skn0tt
Copy link
Member Author

Skn0tt commented Oct 4, 2024

so that it doesn't trigger until there's 100 concurrent requests over the same socket

Now that I think about it, there's no way to send multiple requests concurrently in HTTP/1.1 - that's only added in HTTP2. I'll revert that change.

@Skn0tt
Copy link
Member Author

Skn0tt commented Oct 4, 2024

@mxschmitt could you take a look and make sure that it fixes the error in our python distro?

This comment has been minimized.

@@ -312,8 +312,11 @@ export abstract class APIRequestContext extends SdkObject {

let securityDetails: har.SecurityDetails | undefined;

const cleanup: (() => void)[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

looks like we want eventsHelper.addEventListener instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

that's a nifty helper! done in a483cab

@dgozman
Copy link
Contributor

dgozman commented Oct 4, 2024

I wonder what does this mean for the timings? If the socket is reused, will it get zero connect timings? What if sending does not start right away - should that count as blocked or queued?

This comment has been minimized.

@Skn0tt
Copy link
Member Author

Skn0tt commented Oct 4, 2024

I wonder what does this mean for the timings? If the socket is reused, will it get zero connect timings?

Good question. I'll open a separate issue for us to investigate this.

What if sending does not start right away - should that count as blocked or queued?

That's what https://github.com/nodejs/node/blob/d2ad9b4fb6a6c4d54f14e19e0c74f1285ee5e402/doc/api/http.md#L60-L64 sounds like, yes.

This comment has been minimized.

@Skn0tt Skn0tt merged commit 9a6f03e into microsoft:main Oct 7, 2024
29 checks passed
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Test results for "tests 1"

35822 passed, 619 skipped
✔️✔️✔️

Merge workflow run.

Skn0tt added a commit that referenced this pull request Oct 8, 2024
Closes #32951

`node:http` reuses TCP Sockets under the hood. We weren't cleaning up
our listeners, leading to the `MaxListenersExceededWarning`.

This PR adds cleanup logic. It also raises the warning threshhold, so
that it doesn't trigger until there's 100 concurrent requests over the
same socket.
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.

MaxListenersExceededWarning when running fetch tests
3 participants