Skip to content

Commit 6f9d62e

Browse files
committed
unixgram: close previous vfkit connection using cancel context
1 parent 93920c1 commit 6f9d62e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/crc/cmd/daemon_darwin.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"github.com/pkg/errors"
1414
)
1515

16+
var (
17+
ctx context.Context
18+
cancel context.CancelFunc
19+
)
20+
1621
func vsockListener() (net.Listener, error) {
1722
_ = os.Remove(constants.TapSocketPath)
1823
ln, err := net.Listen("unix", constants.TapSocketPath)
@@ -39,14 +44,19 @@ func unixgramListener(vn *virtualnetwork.VirtualNetwork) (*net.UnixConn, error)
3944
if err != nil {
4045
return conn, errors.Wrap(err, "failed to listen unixgram")
4146
}
42-
logging.Infof("listening on %s:", constants.UnixgramSocketPath)
47+
logging.Infof("listening on %s", constants.UnixgramSocketPath)
4348
vfkitConn, err := transport.AcceptVfkit(conn)
4449
if err != nil {
4550
return conn, errors.Wrap(err, "failed to accept vfkit connection")
4651
}
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())
4757
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 {
5060
logging.Errorf("failed to accept vfkit connection: %v", err)
5161
return
5262
}

0 commit comments

Comments
 (0)