Fix write error handling

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.
This commit is contained in:
Matt Joiner 2022-12-25 19:23:07 +11:00
parent 48ad1a8aca
commit fed765b2a0
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
2 changed files with 21 additions and 0 deletions

View File

@ -104,6 +104,9 @@ func (cn *peerConnMsgWriter) run(keepAliveTimeout time.Duration) {
if err == nil && n != len(next) { if err == nil && n != len(next) {
panic("expected full write") panic("expected full write")
} }
if err != nil {
break
}
} }
if err != nil { if err != nil {
cn.logger.WithDefaultLevel(log.Debug).Printf("error writing: %v", err) cn.logger.WithDefaultLevel(log.Debug).Printf("error writing: %v", err)

18
tests/issue-798/main.go Normal file
View File

@ -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()
}