nareix / joy4

Golang audio/video library and streaming server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nil pointer dereference

suconghou opened this issue · comments

2020/04/18 15:35:51 pull.go:131: 0 dail failed : dial tcp 58.200.131.2:1935: i/o timeout
<nil> 3 1
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc8 pc=0x14007d9]

goroutine 9 [running]:
github.com/nareix/joy4/format/rtmp.(*Conn).prepare(0x0, 0x3, 0x1, 0x18ce180, 0x1e00108)
	/data/go/src/github.com/nareix/joy4/format/rtmp/rtmp.go:805 +0xe9
github.com/nareix/joy4/format/rtmp.(*Conn).Streams(0x0, 0xc0000dde68, 0x107df0c, 0xc0000dde80, 0x100ec08, 0x40)
	/data/go/src/github.com/nareix/joy4/format/rtmp/rtmp.go:850 +0x41
github.com/suconghou/rtmpmirror/rt.toQueue(0xc000072230, 0x15aa840, 0x0, 0xc000311800, 0x2)
	/data/go/src/github.com/suconghou/rtmpmirror/rt/client.go:179 +0x8c
github.com/suconghou/rtmpmirror/rt.loopZone(0xc000072230)
	/data/go/src/github.com/suconghou/rtmpmirror/rt/pull.go:139 +0xb12
created by github.com/suconghou/rtmpmirror/rt.initWorker
	/data/go/src/github.com/suconghou/rtmpmirror/rt/pull.go:52 +0x2c1

prepare function nil dereference when network error or slow or rtmp url conncection reset

I change joy4/format/rtmp/rtmp.go:805 to debug and

fmt.Println print nil


func (self *Conn) prepare(stage int, flags int) (err error) {
	fmt.Println(self, stage, flags)
	for self.stage < stage {
		switch self.stage {
		case 0:
			if self.isserver {
				if err = self.handshakeServer(); err != nil {
					return
				}
			} else {
				if err = self.handshakeClient(); err != nil {
					return
				}
			}

		case stageHandshakeDone:
			if self.isserver {
				if err = self.readConnect(); err != nil {
					return
				}
			} else {
				if flags == prepareReading {
					if err = self.connectPlay(); err != nil {
						return
					}
				} else {
					if err = self.connectPublish(); err != nil {
						return
					}
				}
			}

		case stageCommandDone:
			if flags == prepareReading {
				if err = self.probe(); err != nil {
					return
				}
			} else {
				err = fmt.Errorf("rtmp: call WriteHeader() before WritePacket()")
				return
			}
		}
	}
	return
}

@suconghou , Do you solve this issue?

@mohammadVatandoost maybe,I forget that , you can use https://github.com/suconghou/joy4 and give a try