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(swarm): set default for idle-connection-timeout to 10s #4967

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thomaseizinger
Copy link
Contributor

Description

With the move to a global idle-connection-timeout, connections are being closed much more aggressively. This causes problems in situations where, e.g. an application wants to use a connection shortly after an event has been emitted from the Swarm. With a default of 0 seconds, such a connection is instantly considered idle and therefore closed, despite the application wanting to use it again just moments later. Whilst it is possible to structure application code to mitigate this, it is unnecessarily complicated.

Additionally, connections being closed instantly if not in use is a foot-gun for newcomers to the library.

From a technical point-of-view, instantly closing idle connections is nice. In reality, it is an impractical default. Hence, we change this default to 10s.

10 seconds is considered to be an acceptable default as it strikes a balance between allowing some pause between network activity, yet frees up resources that are (supposedly) no longer needed.

Resolves: #4912.

Notes & open questions

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

@DougAnderson444
Copy link
Contributor

I like this idea. Anyone coming to libp2p is likely going to use their connection for more than 0s, so giving them this default makes sense.

I'm not that familiar with what makes each connection or protocol idle vs what keeps them alive (we recently discusse Ping in #4950 but there are more) -- so neither would other newcomers to libp2p. Could we potentially add this description to the documentation somewhere? It's like Thomas says, we don't need new users fighting against auto-closing connections when they might want to keep an open connection for their app. Another part of this is a note in the docs where applicable.

Thanks for starting this!

@thomaseizinger
Copy link
Contributor Author

I'm not that familiar with what makes each connection or protocol idle vs what keeps them alive (we recently discusse Ping in #4950 but there are more) -- so neither would other newcomers to libp2p. Could we potentially add this description to the documentation somewhere?

The main place where this is currently documented is in https://docs.rs/libp2p/latest/libp2p/swarm/trait.ConnectionHandler.html#method.connection_keep_alive. I think users shouldn't need to know this, only implementers of protocols.

I like this idea. Anyone coming to libp2p is likely going to use their connection for more than 0s, so giving them this default makes sense.

There is some (I guess unintended) irony in this. We automatically keep connections alive while you use them, i.e. while there are active streams.

What this default does is bridge brief moments of inactivity between uses which would otherwise result in an immediate shutdown of the connection because it is idle.

What do you think of the idea voiced in #4912 to not close idle connections at all by default and make it the users responsibility?

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.

Set a better default for idle_connection_timeout
3 participants