Skip to content

Commit

Permalink
Never block a thread on the PeerManager event handling lock
Browse files Browse the repository at this point in the history
If thre's a thread currently handling `PeerManager` events, the
next thread which attempts to handle events will block on the first
and then handle events after the first completes. (later threads
will return immediately to avoid blocking more than one thread).

This works fine as long as the user has a spare thread to leave
blocked, but if they don't (e.g. are running with a single-threaded
tokio runtime) this can lead to a full deadlock.

Instead, here, we never block waiting on another event processing
thread, returning immediately after signaling that the first thread
should start over once its complete to ensure all events are
handled.

While this could lead to starvation as we cause one thread to go
around and around and around again, the risk of that should be
relatively low as event handling should be pretty quick, and it's
certainly better than deadlocking.

Fixes lightningdevkit/rapid-gossip-sync-server#32

Atomic lock simplification suggestion from @andrei-21
  • Loading branch information
TheBlueMatt committed May 24, 2023
1 parent 0ecb4b0 commit 0c034e9
Show file tree
Hide file tree
Showing 2 changed files with 384 additions and 335 deletions.
Loading

0 comments on commit 0c034e9

Please sign in to comment.