@@ -13,9 +13,10 @@ import (
1313// executed the socket name it should listen on to coordinate with the host CLI.
1414const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET"
1515
16- // SetupConn sets up a Unix socket listener, establishes a goroutine to handle connections
17- // and update the conn pointer, and returns the listener for the socket (which the caller
18- // is responsible for closing when it's no longer needed).
16+ // SetupConn sets up a Unix socket listener, establishes a goroutine to handle connections.
17+ // A listener is returned, along with a connection channel that will receive the established
18+ // connection. The channel *may* return a nil connection and should be checked once received.
19+ // The caller is responsible for closing the listener when it's no longer needed.
1920func SetupConn () (* net.UnixListener , <- chan * net.UnixConn , error ) {
2021 listener , err := listen ("docker_cli_" + randomID ())
2122 if err != nil {
@@ -40,11 +41,12 @@ func randomID() string {
4041
4142// accept creates a new Unix socket connection
4243// and sends it to the *net.UnixConn channel
43- // it allows reconnects
4444func accept (listener * net.UnixListener ) <- chan * net.UnixConn {
4545 connChan := make (chan * net.UnixConn , 1 )
4646
4747 go func () {
48+ // close the channel to signal we won't accept any more connections
49+ defer close (connChan )
4850 // this is a blocking call and will wait
4951 // until a new connection is accepted
5052 // or until the timout is reached
@@ -53,8 +55,6 @@ func accept(listener *net.UnixListener) <-chan *net.UnixConn {
5355 // perform any platform-specific actions on accept (e.g. unlink non-abstract sockets)
5456 onAccept (listener )
5557 connChan <- conn
56- // close the channel to signal we won't accept any more connections
57- close (connChan )
5858 }()
5959
6060 return connChan
0 commit comments