1
0
mirror of https://github.com/docker/cli.git synced 2026-01-06 05:41:44 +03:00

plugins: fix plugin socket being closed before use

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm
2024-01-15 14:29:48 +00:00
parent 5f6c55a724
commit 508346ef61
2 changed files with 8 additions and 8 deletions

View File

@@ -14,21 +14,20 @@ import (
const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET"
// SetupConn sets up a Unix socket listener, establishes a goroutine to handle connections
// and update the conn pointer, and returns the environment variable to pass to the plugin.
func SetupConn(conn **net.UnixConn) (string, error) {
// and update the conn pointer, and returns the listener for the socket (which the caller
// is responsible for closing when it's no longer needed).
func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
listener, err := listen("docker_cli_" + uuid.Generate().String())
if err != nil {
return "", err
return nil, err
}
accept(listener, conn)
return EnvKey + "=" + listener.Addr().String(), nil
return listener, nil
}
func accept(listener *net.UnixListener, conn **net.UnixConn) {
defer listener.Close()
go func() {
for {
// ignore error here, if we failed to accept a connection,