@@ -13,6 +13,11 @@ import (
13
13
"github.com/pkg/errors"
14
14
)
15
15
16
+ var (
17
+ ctx context.Context
18
+ cancel context.CancelFunc
19
+ )
20
+
16
21
func vsockListener () (net.Listener , error ) {
17
22
_ = os .Remove (constants .TapSocketPath )
18
23
ln , err := net .Listen ("unix" , constants .TapSocketPath )
@@ -39,14 +44,19 @@ func unixgramListener(vn *virtualnetwork.VirtualNetwork) (*net.UnixConn, error)
39
44
if err != nil {
40
45
return conn , errors .Wrap (err , "failed to listen unixgram" )
41
46
}
42
- logging .Infof ("listening on %s: " , constants .UnixgramSocketPath )
47
+ logging .Infof ("listening on %s" , constants .UnixgramSocketPath )
43
48
vfkitConn , err := transport .AcceptVfkit (conn )
44
49
if err != nil {
45
50
return conn , errors .Wrap (err , "failed to accept vfkit connection" )
46
51
}
52
+ if cancel != nil {
53
+ logging .Warnf ("new connection to %s. Closing old connection" , constants .UnixgramSocketPath )
54
+ cancel ()
55
+ }
56
+ ctx , cancel = context .WithCancel (context .Background ())
47
57
go func () {
48
- err := vn . AcceptVfkit ( context . Background (), vfkitConn )
49
- if err != nil {
58
+ defer vfkitConn . Close ( )
59
+ if err := vn . AcceptVfkit ( ctx , vfkitConn ); err != nil {
50
60
logging .Errorf ("failed to accept vfkit connection: %v" , err )
51
61
return
52
62
}
0 commit comments