Skip to content

Commit

Permalink
fix DATA RACE ws client sender method
Browse files Browse the repository at this point in the history
  • Loading branch information
renat1015 committed Apr 8, 2022
1 parent 227fe28 commit 7d97eb5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ func (c *ClientWs) sender(p bool) error {
return err
}
case <-ticker.C:
c.mu[p].Lock()
if c.conn[p] != nil && (c.lastTransmit[p] == nil || (c.lastTransmit[p] != nil && time.Since(*c.lastTransmit[p]) > PingPeriod)) {
go func() {
c.sendChan[p] <- []byte("ping")
}()
}
c.mu[p].Unlock()
case <-c.ctx.Done():
return c.handleCancel("sender")
}
Expand Down

0 comments on commit 7d97eb5

Please sign in to comment.