Fix race in webtorrent dial stats

This commit is contained in:
Matt Joiner 2021-05-12 14:26:45 +10:00
parent b9c36ebef3
commit bdcba73cf9
1 changed files with 2 additions and 0 deletions

View File

@ -67,7 +67,9 @@ type onDataChannelOpen func(_ datachannel.ReadWriteCloser, dcc DataChannelContex
func (tc *TrackerClient) doWebsocket() error {
metrics.Add("websocket dials", 1)
tc.mu.Lock()
tc.stats.Dials++
tc.mu.Unlock()
c, _, err := websocket.DefaultDialer.Dial(tc.Url, nil)
if err != nil {
return fmt.Errorf("dialing tracker: %w", err)