This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch remove-timer
in repository https://gitbox.apache.org/repos/asf/dubbo-getty.git
The following commit(s) were added to refs/heads/remove-timer by this push:
new 0fb6d79 time.After -> ticker
0fb6d79 is described below
commit 0fb6d79ec156b8c19455aeedea0a13033ac050ea
Author: AlexStocks <[email protected]>
AuthorDate: Sat Jun 11 15:32:32 2022 +0800
time.After -> ticker
---
session.go | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/session.go b/session.go
index cf63342..d64805e 100644
--- a/session.go
+++ b/session.go
@@ -24,6 +24,7 @@ import (
"io"
"net"
"runtime"
+ "runtime/debug"
"sync"
"time"
)
@@ -543,18 +544,20 @@ func (s *session) run() {
}
go func() {
+ ticker := time.NewTicker(s.period)
defer func() {
+ ticker.Stop()
if r := recover(); r != nil {
- log.Errorf("Heartbeat panic occurs, error is
%s", r)
+ log.Errorf("Heartbeat panic occurs, error is
%s, stack %v", r, string(debug.Stack()))
}
}()
for {
select {
case <-s.done: // s.done is a blocked channel. if it
has not been closed, the default branch will be invoked.
return
- case <-time.After(s.period):
+ case <-ticker.C:
if err := heartbeat(s); err != nil {
- log.Errorf("Heartbeat with error: %s",
err)
+ log.Errorf("sessioin %s, heartbeat with
error: %s", s.sessionToken(), err)
}
}
}