From b9c563a581a87e06d54c411143d1b41b9284344b Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 6 Jun 2025 18:30:42 +0200 Subject: [PATCH] only close plugin server if actually created Signed-off-by: Nicolas De Loof --- cmd/docker/docker.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index a7dc49c909..ccd61845a1 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -302,12 +302,12 @@ func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command srv, err := socket.NewPluginServer(nil) if err == nil { plugincmd.Env = append(plugincmd.Env, socket.EnvKey+"="+srv.Addr().String()) + defer func() { + // Close the server when plugin execution is over, so that in case + // it's still open, any sockets on the filesystem are cleaned up. + _ = srv.Close() + }() } - defer func() { - // Close the server when plugin execution is over, so that in case - // it's still open, any sockets on the filesystem are cleaned up. - _ = srv.Close() - }() // Set additional environment variables specified by the caller. plugincmd.Env = append(plugincmd.Env, envs...) @@ -334,7 +334,9 @@ func tryPluginRun(ctx context.Context, dockerCli command.Cli, cmd *cobra.Command // // Repeated invocations will result in EINVAL, // or EBADF; but that is fine for our purposes. - _ = srv.Close() + if srv != nil { + _ = srv.Close() + } // force the process to terminate if it hasn't already if force {