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(swarm): keep connections alive while active streams exist #4595

Merged
merged 56 commits into from
Oct 25, 2023

Conversation

leonzchang
Copy link
Contributor

@leonzchang leonzchang commented Oct 5, 2023

Description

Resolves: #4520.
Related: #4306.

Notes & open questions

Much thanks to @thomaseizinger for the advices!

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Some initial thoughts, thank you for getting this started!

Before we keep on going with the implementation for too long, I'd like us to update the docs on ConnectionHandler::connection_keep_alive to reflect what we are changing here. If you give that a start, it will show up in the diff and I can help out with some comments :)

swarm/src/lib.rs Outdated Show resolved Hide resolved
swarm/src/connection.rs Outdated Show resolved Hide resolved
swarm/src/stream.rs Outdated Show resolved Hide resolved
swarm/src/connection.rs Outdated Show resolved Hide resolved
swarm/src/stream.rs Outdated Show resolved Hide resolved
@leonzchang leonzchang marked this pull request as ready for review October 6, 2023 07:31
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great progress!

Now, to check that this actually works, we need to go through all implementations of ConnectionHandler and remove any code that currently duplicates this kind of stream tracking.

For example here:

fn connection_keep_alive(&self) -> KeepAlive {
if !self.active_streams.is_empty() {
return KeepAlive::Yes;
}
KeepAlive::No
}

This is now unnecessary and can just return KeepAlive::No.

swarm/Cargo.toml Outdated Show resolved Hide resolved
protocols/ping/CHANGELOG.md Outdated Show resolved Hide resolved
swarm/CHANGELOG.md Outdated Show resolved Hide resolved
swarm/src/connection.rs Outdated Show resolved Hide resolved
swarm/src/handler.rs Outdated Show resolved Hide resolved
swarm/src/stream.rs Outdated Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Oct 10, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great progress!

protocols/identify/src/handler.rs Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Oct 13, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks for making the follow-up changes!

Whilst I think we can overall merge these changes (modulo new comments), it would be much cleaner if we'd get rid of KeepAlive::Until first. See #3844. Are you interested in helping out on that front too? :)

protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/perf/src/client/handler.rs Outdated Show resolved Hide resolved
protocols/relay/src/priv_client/handler.rs Outdated Show resolved Hide resolved
protocols/relay/src/behaviour/handler.rs Outdated Show resolved Hide resolved
@leonzchang
Copy link
Contributor Author

leonzchang commented Oct 13, 2023

Thanks for making the follow-up changes!

Whilst I think we can overall merge these changes (modulo new comments), it would be much cleaner if we'd get rid of KeepAlive::Until first. See #3844. Are you interested in helping out on that front too? :)

Do you mean remove KeepAlive::Until in /protocols before this branch merge?
Aye, I can try it out.

@mergify
Copy link
Contributor

mergify bot commented Oct 15, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

@thomaseizinger
Copy link
Contributor

@mxinden Would be great to get your opinion here. We can merge this early by only removing the conditions for stream checks in the protocols where we no longer use KeepAlive::Until. Then this could essentially be released as a patch-release.

I am tempted to do that because it just means that we are doing the bookkeeping twice but it doesn't hurt. We can always remove it at a later stage.

@mergify
Copy link
Contributor

mergify bot commented Oct 16, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

@leonzchang
Copy link
Contributor Author

rebase master

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great progress!

I've left a few more comments. Hope you don't mind :)
Also, if you are interested, we maintainers will meet later today: #4713. If you want, you can present your work here or also just listen in :)

swarm/src/stream.rs Outdated Show resolved Hide resolved
swarm/src/stream.rs Outdated Show resolved Hide resolved
protocols/relay/src/behaviour/handler.rs Outdated Show resolved Hide resolved
protocols/relay/src/priv_client/handler.rs Outdated Show resolved Hide resolved
swarm/CHANGELOG.md Outdated Show resolved Hide resolved
swarm/src/handler.rs Outdated Show resolved Hide resolved
swarm/src/handler/multi.rs Outdated Show resolved Hide resolved
swarm/src/handler/pending.rs Outdated Show resolved Hide resolved
swarm/src/handler/select.rs Outdated Show resolved Hide resolved
swarm/src/keep_alive.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

I updated the docs a bit. This is ready from my end, thank you so much for helping out with this! I am super stoked to land this 🎉

@mxinden Please have a look!

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Lots of simplifications! Well done. Thanks. Also great work on the documentation.

I have a couple of comments. I am sorry in case these have been discussed before.

protocols/gossipsub/src/behaviour.rs Show resolved Hide resolved
protocols/gossipsub/src/handler.rs Show resolved Hide resolved
protocols/ping/src/handler.rs Outdated Show resolved Hide resolved
protocols/relay/src/behaviour/handler.rs Show resolved Hide resolved
swarm/CHANGELOG.md Outdated Show resolved Hide resolved
swarm/CHANGELOG.md Outdated Show resolved Hide resolved
swarm/src/connection.rs Show resolved Hide resolved
swarm/src/handler.rs Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

@leonzchang leonzchang requested a review from mxinden October 25, 2023 05:09
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Great work!

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Well done!

@mergify mergify bot merged commit fcd410a into libp2p:master Oct 25, 2023
71 checks passed
@mxinden
Copy link
Member

mxinden commented Oct 25, 2023

@romanb you might enjoy seeing your proposal from a couple of years ago finally implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-change Pull requests that make internal changes to crates and thus don't need to include a changelog entry. send-it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swarm: Default to keeping connections alive whilst there are active streams
3 participants