Skip to content

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Dec 5, 2024
1 parent b0a3d06 commit fc002f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/solana/client/multinode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ func (m *MultiNodeClient[RPC, HEAD]) UnsubscribeAllExcept(subs ...Subscription)

for sub := range m.subs {
if _, keep := keepSubs[sub]; !keep {
// Release lock to avoid deadlock on unsubscribe
m.subsSliceMu.Unlock()
sub.Unsubscribe()
m.subsSliceMu.Lock()
delete(m.subs, sub)
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/solana/client/multinode/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func TestMultiNodeClient_HeadSubscriptions(t *testing.T) {
sub2.Unsubscribe()
require.Equal(t, 0, c.LenSubs())
})

t.Run("Ensure no deadlock on UnsubscribeAll", func(t *testing.T) {
_, _, err := c.SubscribeToHeads(tests.Context(t))
require.NoError(t, err)
require.Equal(t, 1, c.LenSubs())
_, _, err = c.SubscribeToFinalizedHeads(tests.Context(t))
require.NoError(t, err)
require.Equal(t, 2, c.LenSubs())
c.UnsubscribeAllExcept()
})
}

type mockSub struct {
Expand Down

0 comments on commit fc002f3

Please sign in to comment.