OpenWebTorrent disconnects clients after two minutes of inactivity. In a scenario where an
announce occurs and no other activity occurs for the (default) 120-second idle timer, the
websocket will be torn down by OpenWebTorrent. This in turn causes the tracker client to wait one
minute, reconnect, and reannounce its peers.
This patch sends a websocket.PingMessage every 60 seconds to maintain the connection.
wsConn *websocket.Conn
closed bool
stats TrackerClientStats
wsConn *websocket.Conn
closed bool
stats TrackerClientStats
+ pingTicker *time.Ticker
}
func (me *TrackerClient) Stats() TrackerClientStats {
}
func (me *TrackerClient) Stats() TrackerClientStats {
tc.cond.Broadcast()
tc.mu.Unlock()
tc.announceOffers()
tc.cond.Broadcast()
tc.mu.Unlock()
tc.announceOffers()
+ closeChan := make(chan struct{})
+ go func() {
+ for {
+ select {
+ case <-tc.pingTicker.C:
+ err := c.WriteMessage(websocket.PingMessage, []byte{})
+ if err != nil {
+ return
+ }
+ case <-closeChan:
+ return
+ default:
+ }
+ }
+ }()
err = tc.trackerReadLoop(tc.wsConn)
err = tc.trackerReadLoop(tc.wsConn)
tc.mu.Lock()
c.Close()
tc.mu.Unlock()
tc.mu.Lock()
c.Close()
tc.mu.Unlock()
}
func (tc *TrackerClient) Run() error {
}
func (tc *TrackerClient) Run() error {
+ tc.pingTicker = time.NewTicker(60 * time.Second)
tc.cond.L = &tc.mu
tc.mu.Lock()
for !tc.closed {
tc.cond.L = &tc.mu
tc.mu.Lock()
for !tc.closed {
tc.wsConn.Close()
}
tc.closeUnusedOffers()
tc.wsConn.Close()
}
tc.closeUnusedOffers()
tc.mu.Unlock()
tc.cond.Broadcast()
return nil
tc.mu.Unlock()
tc.cond.Broadcast()
return nil