diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-20 06:38:39 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-20 06:38:39 +0200 |
commit | 18f43705ecbc8751bcf5ed05cd65cf93c36798b0 (patch) | |
tree | 2d19a90e474449a177e392caeb77388d4f76dbde /tun_linux.go | |
parent | 058cedcf664e3bb553e699a09beda4dc5c1474fa (diff) |
Fix race with closing event channel
There's still a tiny race on Linux, since the tun channel is written to
from two places.
Diffstat (limited to 'tun_linux.go')
-rw-r--r-- | tun_linux.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tun_linux.go b/tun_linux.go index 2782260..f9a27d6 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -89,7 +89,10 @@ func createNetlinkSocket() (int, error) { } func (tun *NativeTun) RoutineNetlinkListener() { - defer unix.Close(tun.netlinkSock) + defer func() { + unix.Close(tun.netlinkSock) + close(tun.events) + }() for msg := make([]byte, 1<<16); ; { @@ -357,7 +360,6 @@ func (tun *NativeTun) Close() error { } err2 := tun.fd.Close() err3 := tun.fdCancel.Cancel() - close(tun.events) if err1 != nil { return err1 |