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

feat: unref socket while idle #772

Merged
merged 16 commits into from
Apr 25, 2021
Merged

feat: unref socket while idle #772

merged 16 commits into from
Apr 25, 2021

Conversation

ronag
Copy link
Member

@ronag ronag commented Apr 24, 2021

Allow process shutdown once all requests have completed without
waiting for keepAliveTimeout.

Allow process shutdown once all requests have completed without
waiting for keepAliveTimeout.
@ronag ronag added the Status: help-wanted This issue/pr is open for contributions label Apr 24, 2021
@ronag
Copy link
Member Author

ronag commented Apr 24, 2021

Needs test.

@ronag
Copy link
Member Author

ronag commented Apr 24, 2021

@Ethan-Arrowood ping regarding your question on Slack. If you want to help land please look at making a test.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2021

Codecov Report

Merging #772 (d5ce46e) into main (9f6bf86) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #772    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           24        24            
  Lines         1904      2488   +584     
==========================================
+ Hits          1904      2488   +584     
Impacted Files Coverage Δ
lib/core/symbols.js 100.00% <ø> (ø)
lib/client.js 100.00% <100.00%> (ø)
lib/api/api-stream.js 100.00% <0.00%> (ø)
lib/api/api-connect.js 100.00% <0.00%> (ø)
lib/api/api-request.js 100.00% <0.00%> (ø)
lib/api/api-upgrade.js 100.00% <0.00%> (ø)
lib/api/api-pipeline.js 100.00% <0.00%> (ø)
lib/handler/redirect.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 9f6bf86...d5ce46e. Read the comment docs.

@ronag ronag added this to the 4.0 milestone Apr 24, 2021
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 - having a test will be nice

@ronag
Copy link
Member Author

ronag commented Apr 24, 2021

Added test which unfortunately fails. @mcollina do you know how to debug/check what root ref keeps the process alive?

@ronag
Copy link
Member Author

ronag commented Apr 24, 2021

Maybe @jasnell has some tip on how to debug what ref is keeping the event loop alive?

@Ethan-Arrowood
Copy link
Collaborator

This looks good! I'll try and add some more test cases later today.

@mcollina
Copy link
Member

@ronag
Copy link
Member Author

ronag commented Apr 24, 2021

Yea, so the code works. The problem is the test. I think the server and client needs to run in a separate process for it to work. FYI @Ethan-Arrowood

test/client-unref.js Outdated Show resolved Hide resolved
@Ethan-Arrowood
Copy link
Collaborator

Ethan-Arrowood commented Apr 24, 2021

I'm trying a multi-process test now using worker threads. will report back shortly with what I come up with


I sorta have it working, but not really /testing/ anything. Gotta figure out how to make tap work correctly in a worker thread scenario

@Ethan-Arrowood
Copy link
Collaborator

This is what I have so far: https://gist.github.com/Ethan-Arrowood/30341384a724f944a334b2cae7e4f739

Details in the gist title. Still hacking at it to see if I can get tap to play nicely.

@ronag
Copy link
Member Author

ronag commented Apr 25, 2021

I think you should put the server into the worker, not the other way around.

@Ethan-Arrowood
Copy link
Collaborator

worker_thread test PR is up against this branch (from my fork)

@Ethan-Arrowood
Copy link
Collaborator

Ethan-Arrowood commented Apr 25, 2021

irregardless of the worker thread test. The existing connect-timeout test is failing with this new change. Any ideas? Do we need to keep the client referenced while the request call fails?


making progress. its not the client, its the underlying socket. since this test dereferences the socket in the net.connect override, the client closes itself before processing the request.

* fix unref test to use worker threads

* fix import path
test/client-unref.js Outdated Show resolved Hide resolved
@ronag
Copy link
Member Author

ronag commented Apr 25, 2021

@Ethan-Arrowood I think I managed to fix it.

@ronag ronag force-pushed the unref-when-idle branch 2 times, most recently from b8a7115 to 0cf1e47 Compare April 25, 2021 19:41
@ronag ronag removed the Status: help-wanted This issue/pr is open for contributions label Apr 25, 2021
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 ronag merged commit fba5f10 into main Apr 25, 2021
@Ethan-Arrowood
Copy link
Collaborator

Which release will this be published in? 3 or 4?

@ronag
Copy link
Member Author

ronag commented Apr 25, 2021

4

@ronag ronag deleted the unref-when-idle branch April 25, 2021 22:22
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* feat: unref socket while idle

Allow process shutdown once all requests have completed without
waiting for keepAliveTimeout.

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fixup

* fix unref test to use worker threads (nodejs#775)

* fix unref test to use worker threads

* fix import path

* fixup: connect test

* fixup

* fixup: jest

Co-authored-by: Ethan Arrowood <ethan.arrowood@gmail.com>
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