From bd889f5fe8c5ca2aac979ff9e5242c6d5a51998c Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Mon, 2 Dec 2024 12:12:20 +0300 Subject: [PATCH] Prepare timers for go1.23. (#1552) --- pkg/api/app.go | 5 ++++- pkg/api/metamask/service.go | 5 ++++- pkg/libs/ntptime/ntptime.go | 5 ++++- pkg/node/fsm/tasks/tasks.go | 5 ++++- pkg/node/node.go | 10 ++++++++-- pkg/util/limit_listener/listen.go | 5 ++++- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pkg/api/app.go b/pkg/api/app.go index 8246c12ec..b5d06b772 100644 --- a/pkg/api/app.go +++ b/pkg/api/app.go @@ -111,7 +111,10 @@ func (a *App) TransactionsBroadcast(ctx context.Context, b []byte) (proto.Transa ) defer func() { if !delay.Stop() && !fired { - <-delay.C + select { + case <-delay.C: + default: + } } }() select { diff --git a/pkg/api/metamask/service.go b/pkg/api/metamask/service.go index 721de862d..d19cb85f8 100644 --- a/pkg/api/metamask/service.go +++ b/pkg/api/metamask/service.go @@ -395,7 +395,10 @@ func (s RPCService) Eth_SendRawTransaction(signedTxData string) (proto.EthereumH return proto.EthereumHash{}, errors.New("timeout waiting response from internal FSM") case err := <-respCh: if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } if err != nil { zap.S().Debugf("Eth_SendRawTransaction: error from internal FSM for ethereum tx (ethTxID=%q, to=%q, from=%q): %v", diff --git a/pkg/libs/ntptime/ntptime.go b/pkg/libs/ntptime/ntptime.go index 2e48b257a..07771ae94 100644 --- a/pkg/libs/ntptime/ntptime.go +++ b/pkg/libs/ntptime/ntptime.go @@ -70,7 +70,10 @@ func (a *ntpTimeImpl) Run(ctx context.Context, duration time.Duration) { select { case <-ctx.Done(): if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } return case <-timer.C: diff --git a/pkg/node/fsm/tasks/tasks.go b/pkg/node/fsm/tasks/tasks.go index 37b223c8a..f42e65194 100644 --- a/pkg/node/fsm/tasks/tasks.go +++ b/pkg/node/fsm/tasks/tasks.go @@ -233,7 +233,10 @@ func (a SnapshotTimeoutTask) Run(ctx context.Context, output chan AsyncTask) err t := time.NewTimer(a.timeout) defer func() { if !t.Stop() { - <-t.C + select { + case <-t.C: + default: + } } }() select { diff --git a/pkg/node/node.go b/pkg/node/node.go index f7dad4059..d4cf39bdd 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -222,7 +222,10 @@ func (a *Node) runInternalMetrics(ctx context.Context, ch chan peer.ProtoMessage select { case <-ctx.Done(): if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } return case <-timer.C: @@ -238,7 +241,10 @@ func (a *Node) runOutgoingConnections(ctx context.Context) { select { case <-ctx.Done(): if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } return case <-timer.C: diff --git a/pkg/util/limit_listener/listen.go b/pkg/util/limit_listener/listen.go index 2710b1b4f..5b8c05a44 100644 --- a/pkg/util/limit_listener/listen.go +++ b/pkg/util/limit_listener/listen.go @@ -90,7 +90,10 @@ func (l *limitListener) acquire() bool { timer := time.NewTimer(l.waitConnQuotaTimeout) stopTimer := func() { if !timer.Stop() { - <-timer.C + select { + case <-timer.C: + default: + } } } select {