rwcancel: add an explicit close call
This lets us collect FDs even if the GC doesn't do it for us. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
a97ef39cd4
commit
6f08a10041
@ -49,6 +49,7 @@ func (device *Device) routineRouteListener(bind conn.Bind, netlinkSock int, netl
|
|||||||
var reqPeer map[uint32]peerEndpointPtr
|
var reqPeer map[uint32]peerEndpointPtr
|
||||||
var reqPeerLock sync.Mutex
|
var reqPeerLock sync.Mutex
|
||||||
|
|
||||||
|
defer netlinkCancel.Close()
|
||||||
defer unix.Close(netlinkSock)
|
defer unix.Close(netlinkSock)
|
||||||
|
|
||||||
for msg := make([]byte, 1<<16); ; {
|
for msg := make([]byte, 1<<16); ; {
|
||||||
|
@ -99,6 +99,7 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
|
|||||||
go func(l *UAPIListener) {
|
go func(l *UAPIListener) {
|
||||||
var buff [0]byte
|
var buff [0]byte
|
||||||
for {
|
for {
|
||||||
|
defer uapi.inotifyRWCancel.Close()
|
||||||
// start with lstat to avoid race condition
|
// start with lstat to avoid race condition
|
||||||
if _, err := os.Lstat(socketPath); os.IsNotExist(err) {
|
if _, err := os.Lstat(socketPath); os.IsNotExist(err) {
|
||||||
l.connErr <- err
|
l.connErr <- err
|
||||||
|
@ -119,3 +119,8 @@ func (rw *RWCancel) Cancel() (err error) {
|
|||||||
_, err = rw.closingWriter.Write([]byte{0})
|
_, err = rw.closingWriter.Write([]byte{0})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rw *RWCancel) Close() {
|
||||||
|
rw.closingReader.Close()
|
||||||
|
rw.closingWriter.Close()
|
||||||
|
}
|
||||||
|
@ -106,6 +106,7 @@ func (tun *NativeTun) routineNetlinkListener() {
|
|||||||
unix.Close(tun.netlinkSock)
|
unix.Close(tun.netlinkSock)
|
||||||
tun.hackListenerClosed.Lock()
|
tun.hackListenerClosed.Lock()
|
||||||
close(tun.events)
|
close(tun.events)
|
||||||
|
tun.netlinkCancel.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for msg := make([]byte, 1<<16); ; {
|
for msg := make([]byte, 1<<16); ; {
|
||||||
|
Loading…
Reference in New Issue
Block a user