Skip to content

Commit

Permalink
Fix race condition in electrumx client
Browse files Browse the repository at this point in the history
Previously, the request ID stored in the client was incremented while
the lock was held, however it was then read without the lock being held.
  • Loading branch information
joshuasing committed Feb 26, 2024
1 parent 7c778c0 commit 4a2afcc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hemi/electrumx/electrumx.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func (c *Client) call(ctx context.Context, method string, params, result any) er
defer conn.Close()

c.mtx.Lock()
c.id++
id := c.id++

Check failure on line 126 in hemi/electrumx/electrumx.go

View workflow job for this annotation

GitHub Actions / Build (1.22.x)

syntax error: unexpected ++ at end of statement

Check failure on line 126 in hemi/electrumx/electrumx.go

View workflow job for this annotation

GitHub Actions / Build (1.22.x)

expected ';', found '++'
c.mtx.Unlock()

req := &JSONRPCRequest{
JSONRPC: "2.0",
Method: method,
ID: c.id,
ID: id,
}
if params != any(nil) {
b, err := json.Marshal(params)
Expand Down

0 comments on commit 4a2afcc

Please sign in to comment.