问题
今天使用Golang打印进程PID,程序居然崩了,报错信息如下:
2020/11/27 16:21:15 http: panic serving [::1]:57413: runtime error: invalid memory address or nil pointer dereference
goroutine 72 [running]:
net/http.(*conn).serve.func1(0xc0017228c0)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:1801 +0x147
panic(0x450f460, 0x48ee120)
/usr/local/Cellar/go/1.15.4/libexec/src/runtime/panic.go:975 +0x47a
/Monibuca/plugin-record.(*Encoder).SaveVideo(0xc0000100c0, 0x45c77d5, 0x40, 0xc000024ae0, 0x11, 0x45b16dd, 0x15, 0x0, 0x0, 0x0, ...)
/Users/lz/job/ms/boliving/plugins/plugin-record/ffmpeg.go:260 +0x187
/Monibuca/plugin-record.SaveMp4(0xc00138e7b0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/lz/job/ms/boliving/plugins/plugin-record/mp4.go:54 +0x30d
/Monibuca/plugin-record.run.func2(0x4650580, 0xc0004b00e0, 0xc001cba100)
/Users/lz/job/ms/boliving/plugins/plugin-record/main.go:92 +0xa2d
net/http.HandlerFunc.ServeHTTP(0x45d2200, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2042 +0x44
net/http.(*ServeMux).ServeHTTP(0x48fd700, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2417 +0x1ad
net/http.serverHandler.ServeHTTP(0xc0004b0000, 0x4650580, 0xc0004b00e0, 0xc001cba100)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2843 +0xa3
net/http.(*conn).serve(0xc0017228c0, 0x4651b00, 0xc0014220c0)
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:1925 +0x8ad
created by net/http.(*Server).Serve
/usr/local/Cellar/go/1.15.4/libexec/src/net/http/server.go:2969 +0x36c
解决
代码单元测试也是通过的,为什么集成到系统里就崩溃了呢?
后来尝试了很多别的方法,最后通过单独启用一个新协程方法就解决了。至今不明白为啥,但是解决方法有了。
先记录一下,方便以后回顾思考。