Skip to content
Browse files

Fix improper cleanup when creating a unix socket

  • Loading branch information...
RenaudWasTaken committed May 30, 2019
1 parent 39aeaac commit 7cd575064a86f11ced2ac5d07c2cc19b49db19ca
Showing with 21 additions and 1 deletion.
  1. +21 −1 pkg/kubelet/util/util_unix.go
@@ -20,6 +20,7 @@ package util

import (
@@ -51,7 +52,26 @@ func CreateListener(endpoint string) (net.Listener, error) {
return nil, fmt.Errorf("failed to unlink socket file %q: %v", addr, err)

return net.Listen(protocol, addr)
// Create the socket on a tempfile and move it to the destination socket to handle improprer cleanup
file, err := ioutil.TempFile("", "")
if err != nil {
return nil, fmt.Errorf("failed to create temporary file: %v", err)

if err := os.Remove(file.Name()); err != nil {
return nil, fmt.Errorf("failed to remove temporary file: %v", err)

l, err := net.Listen(protocol, file.Name())
if err != nil {
return nil, err

if err = os.Rename(file.Name(), addr); err != nil {
return nil, fmt.Errorf("failed to move temporary file to addr %q: %v", addr, err)

return l, nil

// GetAddressAndDialer returns the address parsed from the given endpoint and a dialer.

0 comments on commit 7cd5750

Please sign in to comment.
You can’t perform that action at this time.