]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix write error handling
authorMatt Joiner <anacrolix@gmail.com>
Sun, 25 Dec 2022 08:23:07 +0000 (19:23 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 25 Dec 2022 08:24:16 +0000 (19:24 +1100)
Fixes https://github.com/anacrolix/torrent/issues/798.

Prior to this fix, it looks like the writer would just keep writing chunks of the front buffer (incorrectly if there was an error), until presumably the writer would be killed by read hangup elsewhere.

peer-conn-msg-writer.go
tests/issue-798/main.go [new file with mode: 0644]

index 0dbc4ead45c4ee27c73e5edf1a3ccee9878cdb48..1bacc59d188c59ceb726abf4911939092ac9f574 100644 (file)
@@ -104,6 +104,9 @@ func (cn *peerConnMsgWriter) run(keepAliveTimeout time.Duration) {
                        if err == nil && n != len(next) {
                                panic("expected full write")
                        }
+                       if err != nil {
+                               break
+                       }
                }
                if err != nil {
                        cn.logger.WithDefaultLevel(log.Debug).Printf("error writing: %v", err)
diff --git a/tests/issue-798/main.go b/tests/issue-798/main.go
new file mode 100644 (file)
index 0000000..3b9ad64
--- /dev/null
@@ -0,0 +1,18 @@
+package main
+
+import (
+       "fmt"
+       "github.com/anacrolix/torrent"
+)
+
+func main() {
+       config := torrent.NewDefaultClientConfig()
+       config.DataDir = "./output"
+       c, _ := torrent.NewClient(config)
+       defer c.Close()
+       t, _ := c.AddMagnet("magnet:?xt=urn:btih:99c82bb73505a3c0b453f9fa0e881d6e5a32a0c1&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce&tr=https%3A%2F%2Fipv6.torrent.ubuntu.com%2Fannounce")
+       <-t.GotInfo()
+       fmt.Println("start downloading")
+       t.DownloadAll()
+       c.WaitAll()
+}
\ No newline at end of file