anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.39k stars 615 forks source link

x/exp: breaking changes support #859

Closed AskAlexSharov closed 10 months ago

AskAlexSharov commented 10 months ago

github.com/lispad/go-generics-tools is not compatible with recent x/exp breaking changes: they change API of sorting functions from Less bool to Compare int for example slices.SortFunc

github.com/lispad/go-generics-tools@v1.1.0/binheap/topstream.go:48:26: type func(x T, y T) bool of h.comparator does not match inferred type func(a T, b T) int for func(a E, b E) int

does it make sense for+upgrade go-generics-tools or switch to some other binheap?

There is using Multiless package - which also (maybe) not compatible with Compare int API.

x/exp did change API because of new go1.21 package cmp: https://pkg.go.dev/cmp

anacrolix commented 10 months ago

I am disappointed that Ian Lance Taylor is curmudgeonly about so many changes but is happy to break this needlessly.

I have switched to a genericized version of the standard library heap instead.

AskAlexSharov commented 10 months ago

@anacrolix hi. seems this commit - introduced some deadlock. CI is red https://github.com/anacrolix/torrent/actions/runs/5877936323/job/15939030611 and my app can't shutdown on ctrl+c

not sure - if it's related, i see next trace:

1: 6144 [1: 6144] @ 0x1007e0646 0x100091379 0x1007e3e8e 0x1007e3e74 0x1007e378e 0x1007e181c 0x1007df7ed 0x1007df78a 0x1007e014a 0x1009988b4 0x10099a726 0x10099aa87 0x1009a1518 0x100974dd0 0x100974cb4 0x10152b6bc 0x10152a139 0x101527132 0x1005b12e4 0x1000735a1
#   0x1007e0645 github.com/ajwerner/btree/internal/abstract.getNodePool[...].func1+0x25         github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/internal/abstract/node_pool.go:39
#   0x100091378 sync.(*Pool).Get+0xb8                                   sync/pool.go:151
#   0x1007e3e8d github.com/ajwerner/btree/internal/abstract.(*nodePool[...]).getLeafNode+0x10d      github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/internal/abstract/node_pool.go:59
#   0x1007e3e73 github.com/ajwerner/btree/internal/abstract.(*Node[...]).split+0xf3         github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/internal/abstract/node.go:287
#   0x1007e378d github.com/ajwerner/btree/internal/abstract.(*Node[...]).insert+0x1ad           github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/internal/abstract/node.go:357
#   0x1007e181b github.com/ajwerner/btree/internal/abstract.(*Map[...]).Upsert+0x2fb            github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/internal/abstract/aug_btree.go:127
#   0x1007df7ec github.com/ajwerner/btree.(*Set[...]).Upsert+0x8c                   github.com/ajwerner/btree@v0.0.0-20211221152037-f427b3e689c0/btree.go:52
#   0x1007df789 github.com/anacrolix/torrent/request-strategy.(*ajwernerBtree).Add+0x29         github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/request-strategy/ajwerner-btree.go:32
#   0x1007e0149 github.com/anacrolix/torrent/request-strategy.(*PieceRequestOrder).Add+0xc9     github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/request-strategy/piece-request-order.go:47
#   0x1009988b3 github.com/anacrolix/torrent.(*Torrent).addRequestOrderPiece+0xf3           github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/torrent-piece-request-order.go:58
#   0x10099a725 github.com/anacrolix/torrent.(*Torrent).onSetInfo+0x1a5                 github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/torrent.go:485
#   0x10099aa86 github.com/anacrolix/torrent.(*Torrent).setInfoBytesLocked+0x1a6            github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/torrent.go:520
#   0x1009a1517 github.com/anacrolix/torrent.(*Torrent).SetInfoBytes+0x97               github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/torrent.go:1531
#   0x100974dcf github.com/anacrolix/torrent.(*Torrent).MergeSpec+0x8f                  github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/client.go:1414
#   0x100974cb3 github.com/anacrolix/torrent.(*Client).AddTorrentSpec+0x133             github.com/anacrolix/torrent@v1.52.6-0.20230823215932-b836d2ad53ee/client.go:1399
anacrolix commented 10 months ago

I think the CI tests are just a bit flakey. I'm not sure this commit introduced the issue. I could be wrong.

AskAlexSharov commented 10 months ago

Seems I did mistake when tested rollback to prev version. Seems my app stuck on prev version also. Then ball on my side for now.

anacrolix commented 10 months ago

I've pushed https://github.com/anacrolix/torrent/compare/generic-heap-ci-revert?expand=1 to test your theory, but I'm pretty sure it's just flakey tests. Thanks for following up.

AskAlexSharov commented 10 months ago

seems i fixed my app shutdown issue. not related to the torrent lib. thank you.

anacrolix commented 10 months ago

There is an significant issue caused by the heap change. I'm investigating.

anacrolix commented 10 months ago

There was serious behaviour bug fixed in 87f6cdc1e96fdd846bb9c55cfd5176a17373d4b6.