diff options
author | Keuin <[email protected]> | 2022-09-07 10:46:33 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-09-07 10:46:33 +0800 |
commit | c78edaa0ffa28bb360663f172e98540b7978e9b2 (patch) | |
tree | 6e99ca4c42d31eb8516fe8b16a445f3618530948 /bilibili/streaming.go | |
parent | fd48122ae9c340b867bb31dbbde6a3b7a4667944 (diff) |
Handle error correctly when copying live stream.
Diffstat (limited to 'bilibili/streaming.go')
-rw-r--r-- | bilibili/streaming.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/bilibili/streaming.go b/bilibili/streaming.go index cc915a3..ec99565 100644 --- a/bilibili/streaming.go +++ b/bilibili/streaming.go @@ -59,8 +59,17 @@ func (b Bilibili) CopyLiveStream( defer cancelGuardian() // blocking copy - n, err := io.Copy(out, resp.Body) + n, err, isCancelled := common.Copy(ctx, out, resp.Body) + if isCancelled { + // cancelled by context + // this error is useless + err = nil + } + if !isCancelled && err != nil { + // real error happens + b.error.Printf("Stream copying was interrupted unexpectedly: %v", err) + } b.info.Printf("Bytes copied: %v", n) - return + return err } |