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: close connections after use #2520

Closed
wants to merge 2 commits into from

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented May 2, 2024

Historically we've not tried to close connections after they've been opened because we let the connection pruner do that when it's required.

This leads to high resource usage and requires the pruner to be able to select the best connections for pruning which without the context of their intended use is a guessing game.

A distinction is drawn between protocols that have a definite purpose (e.g. kad-dht) and "speculative" protocols that are run on newly opened connections for other purposes, e.g. identify, auto nat, etc.

For example if kad-dht opens a connection to send a message, we can close that connection if the only protocol running on it is identify.

  • Where protocols open connections that are not expected to be long-lived, try to close them if we are done
  • Check the number of open streams on a connection before closing, if there are none or they are only speculative protocols, close the connection
  • Sort connections by number of open streams in the pruner before pruning

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Historically we've not tried to close connections after they've been
opened because we let the connection pruner do that when it's
required.

This leads to high resource usage and requires the pruner to be able
to select the best connections for pruning which without the context
of their intended use is a guessing game.

- Where protocols open connections that are not expected to be long-lived, try to close them if we are done
- Check the number of open streams on a connection before closing, if there are none or they are only speculative protocols, close the connection
- Sort connections by number of open streams in the pruner before pruning
@achingbrain achingbrain requested a review from a team as a code owner May 2, 2024 12:24
@achingbrain achingbrain marked this pull request as draft May 2, 2024 12:30
@achingbrain
Copy link
Member Author

Closing as the connection pruner now closes connections without streams first.

@achingbrain achingbrain deleted the fix/close-connections-after-use branch May 14, 2024 09:05
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.

None yet

1 participant