garlic
garlic copied to clipboard
How to tell if a socket is closed?
I'm using this package to monitor proc event。I receive msg by ReadPCN
, and when the socket has something problems,I got one error. And I try to ClosePCN
and restart all steps again, but I found that when the error is EBADF
, my program panic with close of closed channel
:
panic: close of closed channel
goroutine 11 [running]:
panic(0x805f80, 0x90fa50)
/usr/local/go/src/runtime/panic.go:1060 +0x420 fp=0xc0001f1ce8 sp=0xc0001f1c40 pc=0x435680
runtime.closechan(0xc0001266c0)
/usr/local/go/src/runtime/chan.go:343 +0x251 fp=0xc0001f1d28 sp=0xc0001f1ce8 pc=0x407401
github.com/mdlayher/netlink.(*lockedNetNSGoroutine).stop(...)
/data/src/github.com/mdlayher/netlink/conn_linux.go:760
github.com/mdlayher/netlink.(*sysSocket).Close(0xc00024fcb0, 0x0, 0x0)
/data/src/github.com/mdlayher/netlink/conn_linux.go:511 +0x9c fp=0xc0001f1d80 sp=0xc0001f1d28 pc=0x777bcc
github.com/mdlayher/netlink.(*conn).Close(0xc00022ee40, 0x12, 0xc0008461e0)
/data/src/github.com/mdlayher/netlink/conn_linux.go:189 +0x37 fp=0xc0001f1db8 sp=0xc0001f1d80 pc=0x776bf7
github.com/mdlayher/netlink.(*Conn).Close(...)
/data/src/github.com/mdlayher/netlink/conn.go:109
github.com/fearful-symmetry/garlic.CnConn.ClosePCN(0xc000119fc0, 0x5d3b0405, 0x12, 0xc0008461e0)
/data/src/github.com/fearful-symmetry/garlic/garlic.go:94 +0x37 fp=0xc0001f1df0 sp=0xc0001f1db8 pc=0x77d207
so, i want to close conn safely by check whether the conn is closed, but I can't find any API to do this, can you help me?
thanks!