libp2p / libp2p/rust-libp2p

swarm: connection management behaviours can lead to inconsistent state

Open
#4,870 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.6k
Forks
1.3k
Avg merge
8h 47m
Merged PRs (30d)
19

Description

In #4777, we discovered that a "connection management" behaviour like libp2p-connection-limits can lead to inconsistent state if it is not applied "first" in the tree of behaviours.

That is because the handle_ functions take &mut self and thus allow modifying the state of a NetworkBehaviour, potentially pre-loading a handler with state. If a behaviour deeper in the tree ends up rejecting the connection, that state is lost.

Preloading handlers is useful to ensure they don't "instant timeout" based on keep-alive after a connection has been established.

The underlying design issue here is that the composition of handle_ functions leads to an inconsistent view across the state of NetworkBehaviours. By having them take &self, this issue would not occur (unless the user users internal mutability but that we can't guard against).

Somehow, we'd need to find a way to still pass data to the handler but only in case the connection is fully established. Perhaps we should find a way to mitigate the "instant shutdown" in a different way by not starting the Connection task until the ConnectionEstablished event has been dispatched to the behaviour?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading issue #4777 and tracing the NetworkBehaviour handle_ functions involved in connection management and handler preloading. Determine how composed behaviours can avoid retaining state when a deeper behaviour rejects a connection; done requires an agreed design and corresponding coverage, but no file or test is named here.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.