Skip to content

Commit

Permalink
Wrapping request client calls with a read/write mutex
Browse files Browse the repository at this point in the history
It happens that keep-core client panics when interacting with the
go-electrum library. We noticed "concurrent write to websocket connection" error
was thrown when calling GetLatestBlockHeight() function. The stack trace
leads to gorilla/websocket/WriteMessage which is called from the
go-electrum client. The latest block height call was already wrapped
with a read mutex, but we should also wrap it with the write mutex as
well to prevent such concurrent errors.
  • Loading branch information
dimpar committed Aug 24, 2023
1 parent c83fc9a commit cab1168
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/bitcoin/electrum/electrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@ func requestWithRetry[K interface{}](
requestCtx, requestCancel := context.WithTimeout(ctx, c.config.RequestTimeout)
defer requestCancel()

c.clientMutex.RLock()
c.clientMutex.Lock()
r, err := requestFn(requestCtx, c.client)
c.clientMutex.RUnlock()
c.clientMutex.Unlock()

if err != nil {
return fmt.Errorf("request failed: [%w]", err)
Expand Down

0 comments on commit cab1168

Please sign in to comment.