Skip to content

Commit 8fe755d

Browse files
crypto-facsyihuang
authored andcommitted
fix newPendingTransactions subscription deadlock issue (backport evmos#933)
1 parent ad83067 commit 8fe755d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040
### Bug Fixes
4141

4242
* (rpc) [crypto-org-chain#42](https://github.com/crypto-org-chain/ethermint/pull/42) Fix `eth_getLogs` when specify blockHash without address/topics, and limit the response size.
43+
* (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. (backport: #933)
4344

4445
### Bug Fixes
4546

rpc/websockets.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,16 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro
706706
api.logger.Debug("error writing header, will drop peer", "error", err.Error())
707707

708708
try(func() {
709+
// Release the initial read lock in .RUnlock() before
710+
// invoking .Lock() to avoid the deadlock in
711+
// https://github.com/tharsis/ethermint/issues/821#issuecomment-1033959984
712+
// and as documented at https://pkg.go.dev/sync#RWMutex
713+
api.filtersMu.RUnlock()
709714
api.filtersMu.Lock()
710-
defer api.filtersMu.Unlock()
715+
defer func() {
716+
api.filtersMu.Unlock()
717+
api.filtersMu.RLock()
718+
}()
711719

712720
if err != websocket.ErrCloseSent {
713721
_ = wsSub.wsConn.Close()

0 commit comments

Comments
 (0)