Skip to content

Commit e176027

Browse files
committed
socket: try removing is socket-location is a directory
Due to race-conditions between containers starting and the Docker remote API being up, containers bind-mounting the docker-socket may cause the socket-path to be created as a directory. This patch will attempt to remove the directory in such situations. Removing will fail if the directory is not empty. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c833fcd commit e176027

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

sockets/unix_socket.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ func WithChmod(mask os.FileMode) SockOption {
7979

8080
// NewUnixSocketWithOpts creates a unix socket with the specified options
8181
func NewUnixSocketWithOpts(path string, opts ...SockOption) (net.Listener, error) {
82+
// Using syscall.Unlink(), not os.Remove() to prevent deleting the socket if it's in use
8283
if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {
84+
if err == syscall.EISDIR {
85+
err = syscall.Rmdir(path)
86+
}
8387
return nil, err
8488
}
8589
mask := syscall.Umask(0777)

0 commit comments

Comments
 (0)