Merge pull request #6123 from ndeloof/pluginserver

only close plugin server if actually created
This commit is contained in:
Sebastiaan van Stijn 2025-06-10 15:12:06 +02:00 committed by GitHub
commit 5487986681
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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 {