nareix / joy4

Golang audio/video library and streaming server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Random Server Panic Events (nil pointer dereference) when processing RTMP Streams

Abhin33t opened this issue · comments

Hello

Often, the following nil pointer de-reference error has been occurring with the RTMP servers quite randomly -

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x6ed13e]
goroutine 149 [running]:
github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.createURL(0xc0003e2900, 0x1f, 0xc0003cc034, 0x4, 0xc0003cc1e0, 0x7, 0x0)
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:345 +0x22e
github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.(*Conn).readConnect(0xc000580900, 0x0, 0x0)
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:482 +0xf25
github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.(*Conn).prepare(0xc000580900, 0x2, 0x0, 0x0, 0x0)
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:818 +0x173
github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.(*Server).handleConn(0xc000246b10, 0xc000580900, 0x0, 0x0)
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:67 +0x75
github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe.func1(0xc000246b10, 0xc000580900)
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:118 +0x39
created by github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp.(*Server).ListenAndServe
        /home/user/go/src/github.com/livego2/vendor/github.com/nareix/joy4/format/rtmp/rtmp.go:117 +0x1a2

Following the stack-trace reveals that the tcurl Host doesn't set after url.Parse call (although the exact reason isn't known necessitating a deep-dive):

if tcurl != "" {
		tu, _ := url.Parse(tcurl)
		if tu != nil {
			u.Host = tu.Host
			u.Scheme = tu.Scheme
		}
	} 

I suspect it might be related to disconnection issues although that's a guess.
Has anyone else encountered this issue?
Are there any suggested remedial actions to undertake to find the root cause?
The issue replication has proved to be elusive so far.

Thanks