Skip to content

TorrServer crash with anacrolix/torrent@master #1035

@tsynik

Description

@tsynik

Hi, @anacrolix!
I have new attemt to adopt TorrServer to current library. In general it works great, but there is few issues:

1st one - torrent spam syslog with ReadAt errors when reading of closed torrent. I muted YouROK/TorrServer@21443ad#diff-542ab524afe879ecc784528fcd59a5cd3851df12a5585f434bb43427dde7f235 such messages with custom Slogger implementation: https://github.com/YouROK/TorrServer/blob/44077202e34d04fd85dd38fdf1699497735c53a0/server/log/log.go#L125-L197. This stop spamming of syslog to hundred of GB but looks like doesn't help avoid crashes with stack overflow.

And even with null slog from library I have stack overflow in reader waitAvailable:

reader-waitAvailable-stack-overflow.txt

full-crash-log.txt

This is our preload readers implementation: https://github.com/YouROK/TorrServer/blob/new-engine/server/torr/preload.go
There is check of closed torrent before readers start https://github.com/YouROK/TorrServer/blob/44077202e34d04fd85dd38fdf1699497735c53a0/server/torr/preload.go#L87-L90, but situation when user cancels preload and readers are still active also possible.

Also, there is panic on some trackers when AddToorentSpec:

2025/12/17 02:14:02 New torrent e6e71c1093932619dbd8d260cae3f6f57ac1c2b1
panic: unknown scheme

goroutine 66481 [running]:
github.com/anacrolix/missinggo/v2/panicif.Err(...)
	github.com/anacrolix/missinggo/[email protected]/panicif/panicif.go:49
github.com/anacrolix/torrent.(*regularTrackerAnnounceDispatcher).initTrackerClient(0x3cf0d40, 0x5a10050, {0x580ca38, 0x18}, 0x3d41208, {{0x1, {0x0, 0x0, 0x0}, {0x0, ...}, ...}})
	github.com/anacrolix/[email protected]/client-tracker-announcer.go:857 +0x4b4
github.com/anacrolix/torrent.(*Client).startTrackerAnnouncer(...)
	github.com/anacrolix/[email protected]/client-tracker-announcer.go:784
github.com/anacrolix/torrent.(*Torrent).startScrapingTrackerWithInfohash.func1(...)
	github.com/anacrolix/[email protected]/torrent.go:2212
github.com/anacrolix/torrent.(*Torrent).startScrapingTrackerWithInfohash(0x4bbeb08, 0x5a10050, {0x580ca38, 0x18}, {0xe6, 0xe7, 0x1c, 0x10, 0x93, 0x93, ...})
	github.com/anacrolix/[email protected]/torrent.go:2220 +0x268
github.com/anacrolix/torrent.(*Torrent).startScrapingTracker-range1(...)
	github.com/anacrolix/[email protected]/torrent.go:2184
github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.(*Torrent).startScrapingTracker.(*Torrent).iterShortInfohashes.func1.func2(...)
	github.com/anacrolix/[email protected]/torrent.go:3578
github.com/anacrolix/torrent.(*Torrent).eachShortInfohash(...)
	github.com/anacrolix/[email protected]/torrent.go:3590
github.com/anacrolix/torrent.(*Torrent).startScrapingTracker.(*Torrent).iterShortInfohashes.func1(...)
	github.com/anacrolix/[email protected]/torrent.go:3577
github.com/anacrolix/torrent.(*Torrent).startScrapingTracker(0x4bbeb08, {0x580ca38, 0x18})
	github.com/anacrolix/[email protected]/torrent.go:2183 +0x290
github.com/anacrolix/torrent.(*Torrent).startMissingTrackerScrapers(...)
	github.com/anacrolix/[email protected]/torrent.go:2246
github.com/anacrolix/torrent.(*Torrent).addTrackers(0x4bbeb08, {0x5992810, 0x3, 0x4})
	github.com/anacrolix/[email protected]/torrent.go:1925 +0x2d8
github.com/anacrolix/torrent.(*Torrent).MergeSpec(0x4bbeb08, 0x4c2fdf4)
	github.com/anacrolix/[email protected]/client.go:1614 +0x214
github.com/anacrolix/torrent.(*Client).AddTorrentSpec(0x3cf0a08, 0x6656f28)
	github.com/anacrolix/[email protected]/client.go:1570 +0x74
server/torr.NewTorrent(0x6656f28, 0x3e61770)
	server/torr/torrent.go:77 +0x3d8
server/torr.GetTorrent.func1()
	server/torr/apihelper.go:105 +0x16c
created by server/torr.GetTorrent in goroutine 37414
	server/torr/apihelper.go:103 +0x190

with

func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
	// https://github.com/anacrolix/torrent/issues/747
	if bt == nil || bt.client == nil {
		return nil, errors.New("BT client not connected")
	}
	switch settings.BTsets.RetrackersMode {
	case 1:
		spec.Trackers = append(spec.Trackers, [][]string{utils.GetDefTrackers()}...)
	case 2:
		spec.Trackers = nil
	case 3:
		spec.Trackers = [][]string{utils.GetDefTrackers()}
	}

	trackers := utils.GetTrackerFromFile()
	if len(trackers) > 0 {
		spec.Trackers = append(spec.Trackers, [][]string{trackers}...)
	}

	goTorrent, _, err := bt.client.AddTorrentSpec(spec)
	if err != nil {
		return nil, err
	}
...

Do you have any thoughts how to fix such things in proper way? ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions