Close events channel when no status listener

This commit is contained in:
Jason A. Donenfeld 2018-05-21 14:16:46 +02:00
parent 7472930d4e
commit 837a12c841
2 changed files with 10 additions and 3 deletions

View File

@ -303,6 +303,9 @@ func (tun *NativeTun) Close() error {
// Surprisingly, on Darwin, simply closing a route socket is enough to unblock it.
// We don't even need to call shutdown, or use a rwcancel.
err3 = unix.Close(tun.routeSocket)
tun.routeSocket = -1
} else if tun.events != nil {
close(tun.events)
}
if err1 != nil {
return err1

View File

@ -357,9 +357,13 @@ func (tun *NativeTun) Events() chan TUNEvent {
func (tun *NativeTun) Close() error {
var err1 error
close(tun.statusListenersShutdown)
if tun.netlinkCancel != nil {
err1 = tun.netlinkCancel.Cancel()
if tun.statusListenersShutdown != nil {
close(tun.statusListenersShutdown)
if tun.netlinkCancel != nil {
err1 = tun.netlinkCancel.Cancel()
}
} else if tun.events != nil {
close(tun.events)
}
err2 := tun.fd.Close()
err3 := tun.fdCancel.Cancel()