From af9a9e4036c2a7aec052035c9e62301683a9b1e3 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Tue, 21 Mar 2023 23:29:30 +0800 Subject: [PATCH] Fix panic: close of closed channel stream.go:1336 --- Reply/stream.go | 49 ++++++++++++++++++++++++++++++++++++------------- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Reply/stream.go b/Reply/stream.go index 7eb57a4..c75b549 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -628,11 +628,40 @@ func (t *M4SStream) saveStreamFlv() (e error) { return } - // 如果被主动关闭,则退出saveStreamFlv,否则继续尝试其他live - s := signal.Init() + CookieM := make(map[string]string) + t.common.Cookie.Range(func(k, v interface{}) bool { + CookieM[k.(string)] = v.(string) + return true + }) //开始获取 r := t.reqPool.Get() + //检查 + if e := r.Reqf(reqf.Rval{ + Url: surl.String(), + NoResponse: true, + JustResponseCode: true, + Proxy: t.common.Proxy, + Timeout: 5000, + Header: map[string]string{ + `Host`: surl.Host, + `User-Agent`: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`, + `Accept`: `*/*`, + `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`, + `Origin`: `https://live.bilibili.com`, + `Connection`: `keep-alive`, + `Pragma`: `no-cache`, + `Cache-Control`: `no-cache`, + `Referer`: "https://live.bilibili.com/", + `Cookie`: reqf.Map_2_Cookies_String(CookieM), + }, + }); e != nil && reqf.IsTimeout(e) { + t.reqPool.Put(r) + continue + } + + // 如果被主动关闭,则退出saveStreamFlv,否则继续尝试其他live + s := signal.Init() { go func() { tsc, tscf := t.Status.WaitC() @@ -701,7 +730,7 @@ func (t *M4SStream) saveStreamFlv() (e error) { buff.Append(buf[:n]) if e != nil { out.Close() - t.Stream_msg.Push_tag(`close`, nil) + t.Stream_msg.PushLock_tag(`close`, nil) break } leastReadUnix.Store(time.Now().Unix()) @@ -731,13 +760,13 @@ func (t *M4SStream) saveStreamFlv() (e error) { copy(t.first_buf, front_buf) // fmt.Println("write front_buf") out.Write(t.first_buf) - t.Stream_msg.Push_tag(`data`, t.first_buf) + t.Stream_msg.PushLock_tag(`data`, t.first_buf) } if len(t.first_buf) != 0 && keyframe.Size() != 0 { t.bootBufPush(keyframe.GetPureBuf()) keyframe.Reset() out.Write(t.boot_buf) - t.Stream_msg.Push_tag(`data`, t.boot_buf) + t.Stream_msg.PushLock_tag(`data`, t.boot_buf) } if last_available_offset > 1 { // fmt.Println("write Sync") @@ -751,12 +780,6 @@ func (t *M4SStream) saveStreamFlv() (e error) { buff.Reset() }() - CookieM := make(map[string]string) - t.common.Cookie.Range(func(k, v interface{}) bool { - CookieM[k.(string)] = v.(string) - return true - }) - t.log.L(`I: `, `flv下载开始`) r.Reqf(reqf.Rval{ @@ -1002,7 +1025,7 @@ func (t *M4SStream) saveStreamM4s() (e error) { if !keyframe.IsEmpty() { t.bootBufPush(keyframe.GetPureBuf()) keyframe.Reset() - t.Stream_msg.Push_tag(`data`, t.boot_buf) + t.Stream_msg.PushLock_tag(`data`, t.boot_buf) if out != nil { out.Write(t.boot_buf, true) out.Sync() @@ -1084,7 +1107,7 @@ func (t *M4SStream) saveStreamM4s() (e error) { } // 发送空字节会导致流服务终止 - t.Stream_msg.Push_tag(`data`, []byte{}) + t.Stream_msg.PushLock_tag(`data`, []byte{}) if !t.config.save_as_mp4 { // 结束 diff --git a/go.mod b/go.mod index 820998a..d6f5d31 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/gofrs/uuid v4.3.0+incompatible github.com/gotk3/gotk3 v0.6.1 github.com/mdp/qrterminal/v3 v3.0.0 - github.com/qydysky/part v0.24.3 + github.com/qydysky/part v0.24.4 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 golang.org/x/text v0.8.0 diff --git a/go.sum b/go.sum index ffd6f8c..ab5857c 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/qydysky/part v0.24.1 h1:St+338RkG5AGlBpcSq29gK5o4tukFOOX8F5x/TMtQG0= github.com/qydysky/part v0.24.1/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo= github.com/qydysky/part v0.24.3 h1:bRnN+iYydDyYQHjHX+uVQzdSbglmVwwDUz2QSexO/DY= github.com/qydysky/part v0.24.3/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo= +github.com/qydysky/part v0.24.4 h1:JCA1CyggvUNu/B0xKEjnODaUp6rgEi1hjtJwqOTvnaw= +github.com/qydysky/part v0.24.4/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= -- 2.39.2