From a6e4728f260d31934d43cc1a456731b0b7e0118f Mon Sep 17 00:00:00 2001 From: Alexey Sharov Date: Wed, 12 Aug 2026 11:47:54 +0700 Subject: [PATCH 1/2] db/downloader: keep the BT discovery tests off UDP torrent.NewClient binds the dynamic port it got for TCP on UDP as well, for uTP. Windows runners reserve UDP port ranges, so that second bind can fail with WSAEACCES and take NewClient down with it once the library exhausts its listen retries. The tests inject peers by TCP address and already run without DHT, so uTP was never used. Route the three client configs through one helper that disables uTP along with DHT and trackers. --- db/downloader/bt_peer_discovery_test.go | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/db/downloader/bt_peer_discovery_test.go b/db/downloader/bt_peer_discovery_test.go index 0cc14a0a171..2aa92d54af9 100644 --- a/db/downloader/bt_peer_discovery_test.go +++ b/db/downloader/bt_peer_discovery_test.go @@ -38,11 +38,7 @@ func TestBTPeerDiscovery_AddPeersFromENR(t *testing.T) { require.NoError(t, os.WriteFile(filepath.Join(seederDir, testFile), testData, 0o644)) // Start seeder torrent client. - seederCfg := torrent.NewDefaultClientConfig() - seederCfg.DataDir = seederDir - seederCfg.ListenPort = 0 // OS-assigned port - seederCfg.NoDHT = true - seederCfg.DisableTrackers = true + seederCfg := newTestClientConfig(t, seederDir) seederCfg.Seed = true seeder, err := torrent.NewClient(seederCfg) @@ -71,13 +67,7 @@ func TestBTPeerDiscovery_AddPeersFromENR(t *testing.T) { assert.Equal(t, [20]byte(infoHash), best.ChainToml.InfoHash) // Start leecher torrent client. - leecherCfg := torrent.NewDefaultClientConfig() - leecherCfg.DataDir = leecherDir - leecherCfg.ListenPort = 0 - leecherCfg.NoDHT = true - leecherCfg.DisableTrackers = true - - leecher, err := torrent.NewClient(leecherCfg) + leecher, err := torrent.NewClient(newTestClientConfig(t, leecherDir)) require.NoError(t, err) defer leecher.Close() @@ -117,12 +107,7 @@ func TestBTPeerDiscovery_NoBTPort(t *testing.T) { peer := &ChainTomlPeer{ChainToml: *ct, Node: node} - // Create a minimal torrent client for the test. - cfg := torrent.NewDefaultClientConfig() - cfg.DataDir = t.TempDir() - cfg.ListenPort = 0 - cfg.NoDHT = true - client, err := torrent.NewClient(cfg) + client, err := torrent.NewClient(newTestClientConfig(t, t.TempDir())) require.NoError(t, err) defer client.Close() @@ -134,6 +119,20 @@ func TestBTPeerDiscovery_NoBTPort(t *testing.T) { assert.Zero(t, torr.Stats().TotalPeers) } +// newTestClientConfig returns a client that talks to nobody it was not handed +// directly. DisableUTP also keeps the listener off UDP, which the OS may refuse +// on the dynamic port the TCP listener already took. +func newTestClientConfig(t *testing.T, dataDir string) *torrent.ClientConfig { + t.Helper() + cfg := torrent.NewDefaultClientConfig() + cfg.DataDir = dataDir + cfg.ListenPort = 0 + cfg.NoDHT = true + cfg.DisableTrackers = true + cfg.DisableUTP = true + return cfg +} + func buildTestMetainfo(t *testing.T, dir, filename string) metainfo.MetaInfo { t.Helper() info := metainfo.Info{ From b60aab4cadab5962cb6622c35c77094e66feba92 Mon Sep 17 00:00:00 2001 From: Alexey Sharov Date: Wed, 12 Aug 2026 12:01:48 +0700 Subject: [PATCH 2/2] db/downloader: re-trigger CI