erigon icon indicating copy to clipboard operation
erigon copied to clipboard

dl: race in `tracker_scraper.go` and `peerRequestDataReader`

Open AskAlexSharov opened this issue 1 year ago • 1 comments

==================
WARNING: DATA RACE
Read at 0x00c13a98f080 by goroutine 9557:
  github.com/anacrolix/missinggo/v2.(*Event).C()
      /home/ubuntu/go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/event.go:22 +0x3ee
  github.com/anacrolix/torrent.(*trackerScraper).Run()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/tracker_scraper.go:237 +0x3b2
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.func1.gowrap1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2155 +0x33

Previous write at 0x00c13a98f080 by goroutine 9556:
  github.com/anacrolix/missinggo/v2.(*Event).C()
      /home/ubuntu/go/pkg/mod/github.com/anacrolix/missinggo/[email protected]/event.go:23 +0x43e
  github.com/anacrolix/torrent.(*trackerScraper).Run()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/tracker_scraper.go:237 +0x3b2
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.func1.gowrap1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2155 +0x33

Goroutine 9557 (running) created at:
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.func1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2155 +0x5d8
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2157 +0x31c
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2126 +0x4b8
  github.com/anacrolix/torrent.(*Torrent).startMissingTrackerScrapers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2176 +0x16d
  github.com/anacrolix/torrent.(*Torrent).addTrackers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:1889 +0x42c
  github.com/anacrolix/torrent.(*Torrent).AddTrackers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/t.go:322 +0xb9
  github.com/ledgerwatch/erigon-lib/downloader.(*Downloader).addTorrentFilesFromDisk.func1()
      /home/ubuntu/erigon/erigon-lib/downloader/downloader.go:2614 +0x7d
  runtime.deferreturn()
      /usr/local/go/src/runtime/panic.go:602 +0x5d
  github.com/ledgerwatch/erigon-lib/downloader.New()
      /home/ubuntu/erigon/erigon-lib/downloader/downloader.go:392 +0x21c6
  github.com/ledgerwatch/erigon/eth.(*Ethereum).setUpSnapDownloader()
      /home/ubuntu/erigon/eth/backend.go:1425 +0x288
  github.com/ledgerwatch/erigon/eth.New()
      /home/ubuntu/erigon/eth/backend.go:369 +0x1fbc
  github.com/ledgerwatch/erigon/turbo/node.New()
      /home/ubuntu/erigon/turbo/node/node.go:139 +0x124
  main.runErigon()
      /home/ubuntu/erigon/cmd/erigon/main.go:95 +0x53b
  github.com/ledgerwatch/erigon/turbo/app.MakeApp.func1()
      /home/ubuntu/erigon/turbo/app/make_app.go:71 +0x17e
  github.com/urfave/cli/v2.(*Command).Run()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:276 +0x1578
  github.com/urfave/cli/v2.(*App).RunContext()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:333 +0x1274
  github.com/urfave/cli/v2.(*App).Run()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:307 +0xc8
  main.main()
      /home/ubuntu/erigon/cmd/erigon/main.go:51 +0x8d

Goroutine 9556 (running) created at:
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.func1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2155 +0x5d8
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2157 +0x31c
  github.com/anacrolix/torrent.(*Torrent).startScrapingTracker()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2126 +0x4b8
  github.com/anacrolix/torrent.(*Torrent).startMissingTrackerScrapers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2176 +0x16d
  github.com/anacrolix/torrent.(*Torrent).addTrackers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:1889 +0x42c
  github.com/anacrolix/torrent.(*Torrent).AddTrackers()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/t.go:322 +0xb9
  github.com/ledgerwatch/erigon-lib/downloader.(*Downloader).addTorrentFilesFromDisk.func1()
      /home/ubuntu/erigon/erigon-lib/downloader/downloader.go:2614 +0x7d
  runtime.deferreturn()
      /usr/local/go/src/runtime/panic.go:602 +0x5d
  github.com/ledgerwatch/erigon-lib/downloader.New()
      /home/ubuntu/erigon/erigon-lib/downloader/downloader.go:392 +0x21c6
  github.com/ledgerwatch/erigon/eth.(*Ethereum).setUpSnapDownloader()
      /home/ubuntu/erigon/eth/backend.go:1425 +0x288
  github.com/ledgerwatch/erigon/eth.New()
      /home/ubuntu/erigon/eth/backend.go:369 +0x1fbc
  github.com/ledgerwatch/erigon/turbo/node.New()
      /home/ubuntu/erigon/turbo/node/node.go:139 +0x124
  main.runErigon()
      /home/ubuntu/erigon/cmd/erigon/main.go:95 +0x53b
  github.com/ledgerwatch/erigon/turbo/app.MakeApp.func1()
      /home/ubuntu/erigon/turbo/app/make_app.go:71 +0x17e
  github.com/urfave/cli/v2.(*Command).Run()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:276 +0x1578
  github.com/urfave/cli/v2.(*App).RunContext()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:333 +0x1274
  github.com/urfave/cli/v2.(*App).Run()
      /home/ubuntu/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:307 +0xc8
  main.main()
      /home/ubuntu/erigon/cmd/erigon/main.go:51 +0x8d
==================
==================
WARNING: DATA RACE
Write at 0x00c1e377ce80 by goroutine 46822:
  github.com/anacrolix/torrent.(*PeerConn).peerRequestDataReader()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:760 +0x416
  github.com/anacrolix/torrent.(*PeerConn).onReadRequest.gowrap2()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:737 +0x64

Previous read at 0x00c1e377ce80 by goroutine 43871:
  github.com/anacrolix/torrent.(*PeerConn).upload()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:1219 +0x373
  github.com/anacrolix/torrent.(*PeerConn).fillWriteBuffer()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:397 +0x1f4
  github.com/anacrolix/torrent.(*PeerConn).startMessageWriter.(*PeerConn).initMessageWriter.func1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peer-conn-msg-writer.go:22 +0x54
  github.com/anacrolix/torrent.(*peerConnMsgWriter).run()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peer-conn-msg-writer.go:69 +0x124
  github.com/anacrolix/torrent.(*PeerConn).messageWriterRunner()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peer-conn-msg-writer.go:41 +0x11d
  github.com/anacrolix/torrent.(*PeerConn).startMessageWriter.gowrap1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peer-conn-msg-writer.go:36 +0x33

Goroutine 46822 (running) created at:
  github.com/anacrolix/torrent.(*PeerConn).onReadRequest()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:737 +0xbb2
  github.com/anacrolix/torrent.(*PeerConn).mainReadLoop()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peerconn.go:975 +0xa4b
  github.com/anacrolix/torrent.(*Torrent).runHandshookConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:1123 +0x118
  github.com/anacrolix/torrent.(*Torrent).logRunHandshookConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2084 +0x6d
  github.com/anacrolix/torrent.(*Torrent).runHandshookConnLoggingErr()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2091 +0x1f8
  github.com/anacrolix/torrent.(*Client).runReceivedConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:1066 +0x1c9
  github.com/anacrolix/torrent.(*Client).incomingConnection()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:605 +0x3f9
  github.com/anacrolix/torrent.(*Client).acceptConnections.func1.gowrap1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:565 +0x4f

Goroutine 43871 (running) created at:
  github.com/anacrolix/torrent.(*PeerConn).startMessageWriter()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/peer-conn-msg-writer.go:36 +0x2ed
  github.com/anacrolix/torrent.(*Torrent).runHandshookConn.func1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:1112 +0x8f7
  github.com/anacrolix/torrent.(*Torrent).runHandshookConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:1116 +0x64
  github.com/anacrolix/torrent.(*Torrent).logRunHandshookConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2084 +0x6d
  github.com/anacrolix/torrent.(*Torrent).runHandshookConnLoggingErr()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/torrent.go:2091 +0x1f8
  github.com/anacrolix/torrent.(*Client).runReceivedConn()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:1066 +0x1c9
  github.com/anacrolix/torrent.(*Client).incomingConnection()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:605 +0x3f9
  github.com/anacrolix/torrent.(*Client).acceptConnections.func1.gowrap1()
      /home/ubuntu/go/pkg/mod/github.com/erigontech/[email protected]/client.go:565 +0x4f
==================

AskAlexSharov avatar Jul 05 '24 05:07 AskAlexSharov

there is RLock:

me.t.mu.RLock()
wantPeers := me.t.wantPeersEvent.C()
me.t.mu.RUnlock()

but method C does lazy mutation:

if me.ch == nil {
	me.ch = make(chan struct{})
}	

AskAlexSharov avatar Jul 05 '24 06:07 AskAlexSharov