forked from vocdoni/vocdoni-node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multirpc/subpub: fix potential goroutine deadlocks
When the connection to a peer is lost, broadcastHandler errors in its SendMessage call, and the entire goroutine stops. No goroutine will continue receiving on the write channel, and sooner than later, sends to the write channel will start blocking. This starts causing deadlocks further up in IPFSsync. SubPub.Subscribe and SubPub.PeerStreamWrite can now block forever, and further up the chain in IPFSsync, that can mean some goroutines hold onto mutexes forever. On one hand, this chain of events can hang IPFSsync, stopping it from doing anything useful until a restart. On the other hand, it causes goroutine leaks. When more calls to IPFSsync.Handle come through, using new goroutines via the router, those try to grab the deadlocked mutexes and hang forever. First, fix the root cause: peerSub now has a "closed" channel, which gets closed by peersManager when the peer is dropped. Its goroutines, both for reading and writing messages, keep running until that happens. Second, make the symptom of the deadlock less severe: prevent blocking on channel sends forever. Any send on the "write" channel now stops on "closed". And the send on BroadcastWriter, which could also block forever, now has a fallback timeout of five minutes. Updates vocdoni#243. Perhaps not a total fix, as there might be other leaks.
- Loading branch information
Showing
4 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters