Skip to content

tcpreuse: avoid deadlock between listen and close - #3535

Open
felix314159 wants to merge 1 commit into
libp2p:masterfrom
felix314159:master
Open

tcpreuse: avoid deadlock between listen and close#3535
felix314159 wants to merge 1 commit into
libp2p:masterfrom
felix314159:master

Conversation

@felix314159

Copy link
Copy Markdown

Description

ConnMgr.DemultiplexedListen held the connection-manager mutex while acquiring a multiplexed-listener mutex. Listener closure acquired those mutexes in the opposite order while removing itself from the manager.

Concurrent listener registration and closure could therefore deadlock, preventing listener reconfiguration or host shutdown from completing.

Cancel the multiplexed listener under its own mutex, then close and remove it without holding that mutex. Reject new demultiplexed listeners after closure begins and make closure idempotent.

Reproduction

A deterministic regression test pauses underlying listener closure while registering another demultiplexed listener. Before the fix, both operations wait indefinitely on the inverted locks.

Testing

  • go test ./p2p/transport/tcpreuse -run TestConcurrentListenAndCloseDoesNotDeadlock -count=100
  • go test -race ./p2p/transport/tcpreuse
  • go vet ./p2p/transport/tcpreuse
  • go test ./...

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.

1 participant