Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ticker variable outside of loop for keepAliveInterval #180

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (l *loop) Run(connected chan struct{}) (err error) {
}
}()
timeoutTicker := time.NewTicker(l.party.timeout())
//keepAliveTicker := time.NewTicker(l.party.keepAliveInterval())

msgLoop:
for {
pingLoop:
Expand Down Expand Up @@ -107,8 +109,12 @@ msgLoop:
case <-time.After(l.party.keepAliveInterval()):
// Send ping only when there was no write in the keepAliveInterval before
if time.Since(l.hubConn.LastWriteStamp()) > l.party.keepAliveInterval() {
_ = l.hubConn.Ping()
if err = l.hubConn.Ping(); err != nil {
break pingLoop
}
}
// A successful ping or Write shows us that the connection is alive. Reset the timeout
timeoutTicker.Reset(l.party.timeout())
// Don't break the pingLoop when keepAlive is over, it exists for this case
case <-timeoutTicker.C:
err = fmt.Errorf("timeout interval elapsed (%v)", l.party.timeout())
Expand Down