Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: index out of range [0] with length 0 #85

Open
yourchanges opened this issue Apr 9, 2021 · 6 comments
Open

panic: runtime error: index out of range [0] with length 0 #85

yourchanges opened this issue Apr 9, 2021 · 6 comments

Comments

@yourchanges
Copy link

when I try the new version, it panic directly. here is log:

[GIN] 2021/04/09 - 10:28:52 | 200 |     160.161µs |       127.0.0.1 | GET      "/static/js/app.js?ver=2021-04-09%2010%3a28%3a52.597377948%20%2b0800%20CST%20m%3d%2b54.595446870"
2021/04/09 10:28:52 Stream Try Connect MICRO


2021/04/09 10:28:53 [Recovery] 2021/04/09 - 10:28:53 panic recovered:
GET /stream/codec/MICRO HTTP/1.1
Host: localhost:8083
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Cookie: SL_G_WPT_TO=zh-CN; SL_GWPT_Show_Hide_tmp=undefined; SL_wptGlobTipTmp=undefined
Referer: http://localhost:8083/stream/player/MICRO
Sec-Ch-Ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
Sec-Ch-Ua-Mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
X-Requested-With: XMLHttpRequest


runtime error: index out of range [0] with length 0
/home/lee/go/src/runtime/panic.go:88 (0x434fe4)
        goPanicIndex: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsIndex})
/home/lee/gowork/pkg/mod/github.com/deepch/[email protected]/codec/h264parser/parser.go:516 (0xae3fb9)
        CodecData.SPS: return self.RecordInfo.SPS[0]
/home/lee/test/RTSPtoWebRTC/config.go:156 (0xae3cf6)
        (*ConfigST).coGe: if codecVideo.SPS() != nil && codecVideo.PPS() != nil && len(codecVideo.SPS()) > 0 && len(codecVideo.PPS()) > 0 {
/home/lee/test/RTSPtoWebRTC/http.go:67 (0xae5314)
        HTTPAPIServerStreamCodec: codecs := Config.coGe(c.Param("uuid"))
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabcc9a)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0xad0c84)
        RecoveryWithWriter.func1: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabcc9a)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xacfd84)
        LoggerWithConfig.func1: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabcc9a)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:409 (0xac6fd9)
        (*Engine).handleHTTPRequest: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0xac66cc)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/home/lee/go/src/net/http/server.go:2843 (0x6ef582)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/home/lee/go/src/net/http/server.go:1925 (0x6eac8c)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/home/lee/go/src/runtime/asm_amd64.s:1374 (0x46cee0)
        goexit: BYTE    $0x90   // NOP

[GIN] 2021/04/09 - 10:28:53 | 500 |   51.389447ms |       127.0.0.1 | GET      "/stream/codec/MICRO"
2021/04/09 10:28:53 RTSP Signal
2021/04/09 10:28:53 Stream Exit Rtsp Disconnect
2021/04/09 10:28:53 Stream Exit On Demand No Viewer
panic: runtime error: index out of range [0] with length 0

goroutine 198 [running]:
github.com/deepch/vdk/format/rtspv2.(*RTSPClient).RTPDemuxer(0xc00000c780, 0xc00000ef40, 0xc0001fa144, 0x40, 0x40, 0x40)
        /home/lee/gowork/pkg/mod/github.com/deepch/[email protected]/format/rtspv2/client.go:607 +0x2a66
github.com/deepch/vdk/format/rtspv2.(*RTSPClient).startStream(0xc00000c780)
        /home/lee/gowork/pkg/mod/github.com/deepch/[email protected]/format/rtspv2/client.go:290 +0x678
created by github.com/deepch/vdk/format/rtspv2.Dial
        /home/lee/gowork/pkg/mod/github.com/deepch/[email protected]/format/rtspv2/client.go:220 +0x79d

Process finished with exit code 2


it seems should check the length of nal byte array from the code line "for _, nal := range nalRaw {"

@FourLeafTec
Copy link
Contributor

I think it should be Duplicate of #75

@deepch deepch closed this as completed Apr 12, 2021
@yourchanges
Copy link
Author

after upgrade to master, I can see the video stream, but there is still a error message at the first time to open the rtsp stream, here is the log:

[GIN] 2021/04/12 - 11:38:27 | 200 |      60.525µs |       127.0.0.1 | GET      "/static/js/app.js?ver=2021-04-12%2011%3a38%3a27.093925377%20%2b0800%20CST%20m%3d%2b58.741340158"
[GIN] 2021/04/12 - 11:38:27 | 200 |      19.906µs |       127.0.0.1 | GET      "/stream/codec/MICRO"
2021/04/12 11:38:27 Stream Try Connect MICRO


2021/04/12 11:38:27 [Recovery] 2021/04/12 - 11:38:27 panic recovered:
POST /stream/receiver/MICRO HTTP/1.1
Host: localhost:8083
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Content-Length: 5113
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: SL_G_WPT_TO=zh-CN; SL_GWPT_Show_Hide_tmp=undefined; SL_wptGlobTipTmp=undefined
Origin: http://localhost:8083
Referer: http://localhost:8083/stream/player/MICRO
Sec-Ch-Ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
Sec-Ch-Ua-Mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
X-Requested-With: XMLHttpRequest


runtime error: index out of range [0] with length 0
/home/lee/go/src/runtime/panic.go:88 (0x434fe4)
        goPanicIndex: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsIndex})
/home/lee/gowork/pkg/mod/github.com/deepch/[email protected]/codec/h264parser/parser.go:519 (0xae4019)
        CodecData.SPS: return self.RecordInfo.SPS[0]
/home/lee/test/RTSPtoWebRTC/config.go:156 (0xae3d56)
        (*ConfigST).coGe: if codecVideo.SPS() != nil && codecVideo.PPS() != nil && len(codecVideo.SPS()) > 0 && len(codecVideo.PPS()) > 0 {
/home/lee/test/RTSPtoWebRTC/http.go:102 (0xae5932)
        HTTPAPIServerStreamWebRTC: codecs := Config.coGe(c.PostForm("suuid"))
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabccba)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0xad0ca4)
        RecoveryWithWriter.func1: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabccba)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xacfda4)
        LoggerWithConfig.func1: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xabccba)
        (*Context).Next: c.handlers[c.index](c)
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:409 (0xac6ff9)
        (*Engine).handleHTTPRequest: c.Next()
/home/lee/gowork/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0xac66ec)
        (*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/home/lee/go/src/net/http/server.go:2843 (0x6ef5a2)
        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/home/lee/go/src/net/http/server.go:1925 (0x6eacac)
        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/home/lee/go/src/runtime/asm_amd64.s:1374 (0x46cee0)
        goexit: BYTE    $0x90   // NOP

[GIN] 2021/04/12 - 11:38:27 | 500 |    1.016289ms |       127.0.0.1 | POST     "/stream/receiver/MICRO"
2021/04/12 11:38:29 Client Not Send ACK (probably the browser is minimized) or tab not active Close client
2021/04/12 11:38:29 Stream Not Send Video Close
2021/04/12 11:38:31 Client Not Send ACK (probably the browser is minimized) or tab not active Close client
2021/04/12 11:38:31 WritePacket WebRTC Client Offline
2021/04/12 11:38:34 Stream Exit On Demand No Viewer
2021/04/12 11:38:34 Stream Exit On Demand No Viewer
2021/04/12 11:38:47 Stream Exit On Demand No Viewer
2021/04/12 11:38:47 Stream Exit On Demand No Viewer
2021/04/12 11:47:29 Stream Exit Rtsp Disconnect
2021/04/12 11:47:30 Stream Try Connect H264_AAC
[GIN] 2021/04/12 - 11:47:38 | 200 |     950.047µs |       127.0.0.1 | GET      "/stream/player/PCM"
[GIN] 2021/04/12 - 11:47:38 | 200 |      53.505µs |       127.0.0.1 | GET      "/static/js/app.js?ver=2021-04-12%2011%3a47%3a38.390236888%20%2b0800%20CST%20m%3d%2b610.037651677"
[GIN] 2021/04/12 - 11:47:38 | 200 |      38.787µs |       127.0.0.1 | GET      "/stream/codec/PCM"
2021/04/12 11:47:38 Stream Try Connect PCM
2021/04/12 11:47:39 Set ICEServers [stun:stun.l.google.com:19302]
[GIN] 2021/04/12 - 11:47:39 | 200 |  452.227342ms |       127.0.0.1 | POST     "/stream/receiver/PCM"
2021/04/12 11:47:48 Client Not Send ACK (probably the browser is minimized) or tab not active Close client
2021/04/12 11:47:48 WritePacket WebRTC Client Offline
2021/04/12 11:47:51 interrupt
2021/04/12 11:47:51 Exiting


@FourLeafTec
Copy link
Contributor

@yourchanges I have reproduce this problem, reopen this issue please.

@deepch this problem only reproduce on first open stream with "on_demand": false
And the test stream rtsp://121.28.86.42:18888

Log:


2021/04/17 12:07:11 [Recovery] 2021/04/17 - 12:07:11 panic recovered:
GET /stream/codec/H264_AAC/rtsp%253A%252F%252F172.16.10.188%252F HTTP/1.1

Host: 172.16.10.201:8083

Accept: application/json, text/plain, */*

Accept-Encoding: gzip, deflate

Accept-Language: zh-CN,zh-TW;q=0.9,zh;q=0.8,en-US;q=0.7,en;q=0.6,ja-JP;q=0.5,ja;q=0.4

Connection: keep-alive

Origin: http://localhost:8081

Referer: http://localhost:8081/

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36

X-Access-Token: 4eff4665749cb016d9e52a483f83e591db447f606d2d2a1fa2b1b3d77d90a501




runtime error: index out of range [0] with length 0
/usr/local/Cellar/go/1.15.7_1/libexec/src/runtime/panic.go:88 (0x103c244)
	goPanicIndex: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsIndex})
/Users/flt/work/go/pkg/mod/github.com/deepch/[email protected]/codec/h264parser/parser.go:519 (0x11c6a89)
	CodecData.SPS: return self.RecordInfo.SPS[0]
/Users/flt/three_part/RTSPtoWebRTC/config.go:156 (0x19b0cd8)
	(*ConfigST).coGe: if codecVideo.SPS() != nil && codecVideo.PPS() != nil && len(codecVideo.SPS()) > 0 && len(codecVideo.PPS()) > 0 {
/Users/flt/three_part/RTSPtoWebRTC/http.go:72 (0x19b2ebe)
	HTTPAPIServerStreamCodec: codecs := Config.coGe(c.Param("uuid"))
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x197622e)
	(*Context).Next: c.handlers[c.index](c)
/Users/flt/three_part/RTSPtoWebRTC/http.go:170 (0x19b5c45)
	CORSMiddleware.func1: c.Next()
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x197622e)
	(*Context).Next: c.handlers[c.index](c)
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0x19931db)
	RecoveryWithWriter.func1: c.Next()
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x197622e)
	(*Context).Next: c.handlers[c.index](c)
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x1991b04)
	LoggerWithConfig.func1: c.Next()
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0x197622e)
	(*Context).Next: c.handlers[c.index](c)
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:409 (0x19837e7)
	(*Engine).handleHTTPRequest: c.Next()
/Users/flt/work/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0x198327c)
	(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/Cellar/go/1.15.7_1/libexec/src/net/http/server.go:2843 (0x1423e4a)
	serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/Cellar/go/1.15.7_1/libexec/src/net/http/server.go:1925 (0x141e024)
	(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/Cellar/go/1.15.7_1/libexec/src/runtime/asm_amd64.s:1374 (0x1078320)
	goexit: BYTE	$0x90	// NOP

@deepch deepch reopened this Apr 17, 2021
@deepch
Copy link
Owner

deepch commented Apr 17, 2021

Thanks, I'll figure it out tomorrow.

@FourLeafTec
Copy link
Contributor

FourLeafTec commented Apr 25, 2021

@deepch Sorry, i need to close test stream for a several days.
If you need the stream to test, just call me.

@yourchanges
Copy link
Author

Modify the config.go line 186

if len(codecVideo.RecordInfo.SPS) > 0 && len(codecVideo.RecordInfo.PPS) > 0 && codecVideo.SPS() != nil && codecVideo.PPS() != nil && len(codecVideo.SPS()) > 0 && len(codecVideo.PPS()) > 0 {
					

to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants