Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
fix newPendingTransactions subscription deadlock issue (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto-facs authored Feb 10, 2022
1 parent 7b22a53 commit e16b7f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (evm) [tharsis#871](https://github.com/tharsis/ethermint/pull/871) Set correct nonce in `EthCall` and `EstimateGas` grpc query.
* (rpc) [tharsis#878](https://github.com/tharsis/ethermint/pull/878) Workaround to make GetBlock RPC api report correct block gas used.
* (rpc) [tharsis#900](https://github.com/tharsis/ethermint/pull/900) newPendingTransactions filter return ethereum tx hash.
* (rpc) [tharsis#933](https://github.com/tharsis/ethermint/pull/933) Fix newPendingTransactions subscription deadlock when a Websocket client exits without unsubscribing and the node errors.

## [v0.9.0] - 2021-12-01

Expand Down
10 changes: 9 additions & 1 deletion rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,16 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
api.logger.Debug("error writing header, will drop peer", "error", err.Error())

try(func() {
// Release the initial read lock in .RUnlock() before
// invoking .Lock() to avoid the deadlock in
// https://github.com/tharsis/ethermint/issues/821#issuecomment-1033959984
// and as documented at https://pkg.go.dev/sync#RWMutex
api.filtersMu.RUnlock()
api.filtersMu.Lock()
defer api.filtersMu.Unlock()
defer func() {
api.filtersMu.Unlock()
api.filtersMu.RLock()
}()

if err != websocket.ErrCloseSent {
_ = wsSub.wsConn.Close()
Expand Down

0 comments on commit e16b7f8

Please sign in to comment.