keep-network / keep-core

The smart contracts and reference client behind the Keep network
https://keep.network
MIT License
118 stars 73 forks source link

Wrapping request client calls with a read/write mutex #3701

Closed dimpar closed 1 year ago

dimpar commented 1 year ago

Refs https://github.com/keep-network/keep-core/issues/3699

Depends on https://github.com/keep-network/keep-core/pull/3704

It happens that the keep-core client panics when interacting with the go-electrum library. We noticed a "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 library. The latest block height call was already wrapped with a read mutex, but we should also wrap it with the write mutex to prevent such concurrent errors.

dimpar commented 1 year ago

~I wasn't able to recreate the concurrent write to websocket connection error in the integration tests.~ I've added an integration test that hit the GetLatestBlockHeight() concurrently. Without the W lock I was able to replicate the same panic. cab1168 fixed it.