Skip to content

Commit e098311

Browse files
venjiangxiaojian-hong
authored andcommitted
fix: heartbeat send
1 parent 93291ef commit e098311

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

pkg/runtime/conn.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ func (c *ServerConn) getConnType(payload client.NegotiationPayload, conf *Workfl
105105

106106
// Beat sends the heartbeat to clients in every 200ms.
107107
func (c *ServerConn) Beat() {
108-
go func() {
108+
go func(c *ServerConn) {
109+
t := time.NewTicker(200 * time.Millisecond)
109110
for {
110-
// send heartbeat in every 200ms.
111-
time.Sleep(200 * time.Millisecond)
112-
err := c.conn.SendSignal(quic.SignalHeartbeat)
113-
if err != nil {
114-
log.Printf("❌ Server sent SignalHeartbeat to app [%s] failed: %s", c.conn.Name, err.Error())
115-
break
111+
select {
112+
case <-t.C:
113+
err := c.conn.SendSignal(quic.SignalHeartbeat)
114+
if err != nil {
115+
log.Printf("❌ Server sent SignalHeartbeat to app [%s] failed: %s", c.conn.Name, err.Error())
116+
t.Stop()
117+
break
118+
}
116119
}
117120
}
118-
}()
121+
}(c)
119122
}
120123

121124
// Close the QUIC connection.

0 commit comments

Comments
 (0)