-
Notifications
You must be signed in to change notification settings - Fork 984
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
Conversation
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! |
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.
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? |
Is there anything blocking this PR? |
dont believe so unless there are some case points to show 10s isnt enough or too much time. I have no objections to this change though |
df20dbc
to
a83d6b2
Compare
e95fb60
to
cb44c82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok seems ready to be merged now, @dariusc93 @guillaumemichel @elenaf9 @drHuangMHT do you feel this should be a breaking change instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to be a breaking change IMO.
I dont believe this would be a breaking change since its just changing the default value. Of course, I am not sure of who might be using the current default idle timeout either. |
Nah I don't think so. |
The required interop testing could not be done due to this error:
|
Approvals have been dismissed because the PR was updated after the send-it
label was applied.
yeah it's a known issue, see libp2p/test-plans#588 |
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