From a392f389f3ebfcc987dabfc2700c67d6f21306b1 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Wed, 9 Feb 2022 18:27:23 -0500 Subject: [PATCH 1/4] fix newPendingTransactions subscription deadlock issue --- rpc/websockets.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rpc/websockets.go b/rpc/websockets.go index 86629e3488..304d907803 100644 --- a/rpc/websockets.go +++ b/rpc/websockets.go @@ -712,8 +712,12 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro api.logger.Debug("error writing header, will drop peer", "error", err.Error()) try(func() { + 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() From f801fa6432003b46ef28ce696945f1a10983a130 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Wed, 9 Feb 2022 18:36:38 -0500 Subject: [PATCH 2/4] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 598ea49616..f032f2a3a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ## [v0.9.0] - 2021-12-01 From cd336601c2c47c7c5dbe23d152b2e6adbdd0248c Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Wed, 9 Feb 2022 20:54:00 -0500 Subject: [PATCH 3/4] updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f032f2a3a0..3b7a815abd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,7 +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 +* (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 From 730f185b7f70f7472433f5f6a65e05f31b4396b4 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Wed, 9 Feb 2022 20:54:45 -0500 Subject: [PATCH 4/4] add comment --- rpc/websockets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rpc/websockets.go b/rpc/websockets.go index 304d907803..76b5c489c7 100644 --- a/rpc/websockets.go +++ b/rpc/websockets.go @@ -712,6 +712,10 @@ 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 func() {