only close plugin server if actually created

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-06-06 18:30:42 +02:00
parent 9e506545fd
commit b9c563a581
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E

View File

@ -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 {