From 824441efa0f88756a054e2c9d6c25bf0dff6a6fb Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 1 Jul 2017 16:01:38 +1000 Subject: [PATCH] Move logging inside client lock, for Torrent.String Fixes #163 --- reader.go | 2 +- torrent.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/reader.go b/reader.go index 1c8bce79..ed4da8aa 100644 --- a/reader.go +++ b/reader.go @@ -208,8 +208,8 @@ func (r *Reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err erro err = nil return } - log.Printf("error reading torrent %q piece %d offset %d, %d bytes: %s", r.t, pi, po, len(b1), err) r.t.cl.mu.Lock() + log.Printf("error reading torrent %q piece %d offset %d, %d bytes: %s", r.t, pi, po, len(b1), err) r.t.updateAllPieceCompletions() r.t.updateAllPiecePriorities() r.t.cl.mu.Unlock() diff --git a/torrent.go b/torrent.go index f60b3865..337040f5 100644 --- a/torrent.go +++ b/torrent.go @@ -1245,13 +1245,15 @@ func (t *Torrent) dhtAnnouncer() { return } err := t.announceDHT(true) - if err == nil { + func() { cl.mu.Lock() - t.numDHTAnnounces++ - cl.mu.Unlock() - } else { - log.Printf("error announcing %q to DHT: %s", t, err) - } + defer cl.mu.Unlock() + if err == nil { + t.numDHTAnnounces++ + } else { + log.Printf("error announcing %q to DHT: %s", t, err) + } + }() select { case <-t.closed.LockedChan(&cl.mu): return