From ff6c6d4a92b9b19c8ff2c374379c89c0496c772c Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Fri, 7 Feb 2025 16:22:25 +0800 Subject: [PATCH] rpc, eth/filters: use non-blocking timer drain pattern --- eth/filters/api.go | 5 ++++- rpc/websocket.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/eth/filters/api.go b/eth/filters/api.go index e3057a2af2..607dac006d 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -435,7 +435,10 @@ func (api *FilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) { if !f.deadline.Stop() { // timer expired but filter is not yet removed in timeout loop // receive timer value and reset timer - <-f.deadline.C + select { + case <-f.deadline.C: + default: + } } f.deadline.Reset(api.timeout) diff --git a/rpc/websocket.go b/rpc/websocket.go index 9f67caf859..bd7dcdee0b 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -357,7 +357,10 @@ func (wc *websocketCodec) pingLoop() { case <-wc.pingReset: if !pingTimer.Stop() { - <-pingTimer.C + select { + case <-pingTimer.C: + default: + } } pingTimer.Reset(wsPingInterval)