linux环境下loopCloseConn引起的panic #110
Labels
bug
Something isn't working
pending development
Requested PR owner to improve code and waiting for the result
waiting for response
waiting for the response from commenter
Linux环境下使用gnet遇到如下panic,
OnClosed, ts:2020-07-08 15:14:45.124678462 +0800 CST m=+19.847459851, cnn:0xc0002f2000
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x68fad0]
goroutine 530 [running]:
github.com/panjf2000/gnet/ringbuffer.(*RingBuffer).IsEmpty(...)
github.com/panjf2000/gnet/ringbuffer/ring_buffer.go:372
github.com/panjf2000/gnet.(*eventloop).loopCloseConn(0xc0002a6000, 0xc0002f2000, 0x0, 0x0, 0x0, 0xf)
github.com/panjf2000/gnet/eventloop_unix.go:193 +0x30
github.com/panjf2000/gnet.(*conn).Close.func1(0x0, 0x0)
github.com/panjf2000/gnet/connection_unix.go:234 +0x3b
github.com/panjf2000/gnet/internal.(*AsyncJobQueue).ForEach(0xc000290028, 0xc000292000, 0x8)
github.com/panjf2000/gnet/internal/queue.go:56 +0xae
github.com/panjf2000/gnet/internal/netpoll.(*Poller).Polling(0xc000290000, 0xc00017df78, 0x0, 0x0)
github.com/panjf2000/gnet/internal/netpoll/epoll.go:112 +0x29e
github.com/panjf2000/gnet.(*server).activateSubReactor(0xc000164090, 0xc0002a6000)
github.com/panjf2000/gnet/reactor_linux.go:50 +0xb1
github.com/panjf2000/gnet.(*server).startSubReactors.func1.1(0xc000164090, 0xc0002a6000)
github.com/panjf2000/gnet/server_unix.go:91 +0x35
created by github.com/panjf2000/gnet.(*server).startSubReactors.func1
github.com/panjf2000/gnet/server_unix.go:90 +0x6a
产生这个panic的原因:异步多goroutine对conn操作,conn先Close, 后续又另一个AsycWrite,再进入函数
func (el *eventloop) loopCloseConn(c *conn, err error) 时,conn已经被release了,
if !c.outboundBuffer.IsEmpty() && err == nil {
_ = el.loopWrite(c)
}
上面if的判断中c.outboundBuffer 已经是nil,所以发生了panic。
修正建议, 将判断outboundBuffer是否为空的逻辑下移到判断conn是否opened的后面。
The text was updated successfully, but these errors were encountered: