Skip to content

Commit b9c563a

Browse files
committed
only close plugin server if actually created
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 9e50654 commit b9c563a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cmd/docker/docker.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command
302302
srv, err := socket.NewPluginServer(nil)
303303
if err == nil {
304304
plugincmd.Env = append(plugincmd.Env, socket.EnvKey+"="+srv.Addr().String())
305+
defer func() {
306+
// Close the server when plugin execution is over, so that in case
307+
// it's still open, any sockets on the filesystem are cleaned up.
308+
_ = srv.Close()
309+
}()
305310
}
306-
defer func() {
307-
// Close the server when plugin execution is over, so that in case
308-
// it's still open, any sockets on the filesystem are cleaned up.
309-
_ = srv.Close()
310-
}()
311311

312312
// Set additional environment variables specified by the caller.
313313
plugincmd.Env = append(plugincmd.Env, envs...)
@@ -334,7 +334,9 @@ func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command
334334
//
335335
// Repeated invocations will result in EINVAL,
336336
// or EBADF; but that is fine for our purposes.
337-
_ = srv.Close()
337+
if srv != nil {
338+
_ = srv.Close()
339+
}
338340

339341
// force the process to terminate if it hasn't already
340342
if force {

0 commit comments

Comments
 (0)