Skip to content

Commit

Permalink
Merge pull request #91 from anthonyraymond/patch-2
Browse files Browse the repository at this point in the history
Fix heart beat problem in server/client/conn.go closes #66
  • Loading branch information
worg authored Jan 13, 2021
2 parents 9c81a64 + dd67e27 commit 0036ca2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions server/client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ func (c *Conn) processLoop() {

c.writer = frame.NewWriter(c.rw)
c.stateFunc = connecting
for {
var timerChannel <-chan time.Time
var timer *time.Timer

if c.writeTimeout > 0 {
var timerChannel <-chan time.Time
var timer *time.Timer
for {
if c.writeTimeout > 0 && timer == nil {
timer = time.NewTimer(c.writeTimeout)
timerChannel = timer.C
}
Expand Down Expand Up @@ -310,6 +310,11 @@ func (c *Conn) processLoop() {
}

case _ = <-timerChannel:
// stop the heart-beat timer
if timer != nil {
timer.Stop()
timer = nil
}
// write a heart-beat
err := c.writer.Write(nil)
if err != nil {
Expand Down

0 comments on commit 0036ca2

Please sign in to comment.