client-unlock-handlers.go | 15 +++++++++++++-- client_test.go | 1 - deferrwl.go | 2 +- peerconn_test.go | 1 - pexconn_test.go | 1 - diff --git a/client-unlock-handlers.go b/client-unlock-handlers.go index 29011aba87e343bc0a2ca0cfa12004ce4c99851a..e12a0756cc3a19941f62abb8873100235f92079e 100644 --- a/client-unlock-handlers.go +++ b/client-unlock-handlers.go @@ -1,6 +1,9 @@ package torrent import ( + "log/slog" + "time" + g "github.com/anacrolix/generics" "github.com/anacrolix/missinggo/v2/panicif" ) @@ -34,9 +37,12 @@ v.updateComplete = true me.torrentActions[t] = v } -func (me *clientUnlockHandlers) run() { +func (me *clientUnlockHandlers) run(logger *slog.Logger) { + trackers := 0 + started := time.Now() for t, v := range me.torrentActions { if v.updateRegularTrackerAnnouncing { + trackers++ t.updateRegularTrackerAnnouncing() } if v.updateComplete { @@ -44,9 +50,14 @@ t.updateComplete() } delete(me.torrentActions, t) } - panicif.NotEq(len(me.torrentActions), 0) + since := time.Since(started) + // Around here the Go scheduler starts to do crazy stuff. + if since > 20*time.Millisecond { + logger.Warn("client unlock handlers took a long time", "duration", since, "trackers", trackers) + } for p := range me.changedPieceStates { p.publishStateChange() delete(me.changedPieceStates, p) } + panicif.NotEq(len(me.torrentActions), 0) } diff --git a/client_test.go b/client_test.go index ddd16568464162ac981e6dd86a4500158f4456c1..72dce232dde3349e64d2661888d8549d41c6b2f8 100644 --- a/client_test.go +++ b/client_test.go @@ -84,7 +84,6 @@ dir, mi := testutil.GreetingTestTorrent() defer os.RemoveAll(dir) var cl Client cl.init(TestingConfig(t)) - cl.initLogger() tor := cl.newTorrent( mi.HashInfoBytes(), storage.NewFileWithCompletion(t.TempDir(), storage.NewMapPieceCompletion()), diff --git a/deferrwl.go b/deferrwl.go index 4fc3c0af10548833149c80c0c011cc1310a27bc7..c0d55c4577b88c6e283b34f2787f4ca4540591ce 100644 --- a/deferrwl.go +++ b/deferrwl.go @@ -32,7 +32,7 @@ // If this doesn't happen other clean up handlers will block on the lock. defer me.internal.Unlock() panicif.False(me.allowDefers) me.allowDefers = false - me.client.unlockHandlers.run() + me.client.unlockHandlers.run(me.client.slogger) startLen := len(me.unlockActions) var i int for i = 0; i < len(me.unlockActions); i++ { diff --git a/peerconn_test.go b/peerconn_test.go index c331d1a2b40387dcc215dd4f67a355cae8838ee5..867121ae1d739a0395d514f1dfe5272d74b94e59 100644 --- a/peerconn_test.go +++ b/peerconn_test.go @@ -108,7 +108,6 @@ cfg := TestingConfig(b) ts := &torrentStorage{} cfg.DefaultStorage = &torrentStorageClient{ts} cl.init(cfg) - cl.initLogger() t, _ := cl.AddTorrentOpt(AddTorrentOpts{ InfoHash: testingTorrentInfoHash, Storage: &torrentStorageClient{ts}, diff --git a/pexconn_test.go b/pexconn_test.go index 02da7d0a1b57b68f30e1dfaa0da967accca26098..34d539170064b3b42128743c548a7bec3998da2f 100644 --- a/pexconn_test.go +++ b/pexconn_test.go @@ -13,7 +13,6 @@ func TestPexConnState(t *testing.T) { var cl Client cl.init(TestingConfig(t)) - cl.initLogger() torrent := cl.newTorrentForTesting() addr := &net.TCPAddr{IP: net.IPv6loopback, Port: 4747} c := cl.newConnection(nil, newConnectionOpts{