From c78edaa0ffa28bb360663f172e98540b7978e9b2 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 7 Sep 2022 10:46:33 +0800 Subject: Handle error correctly when copying live stream. --- bilibili/streaming.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bilibili') 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 } -- cgit v1.2.3