@@ -46,20 +46,21 @@ const (
46
46
// Note that due to the retry logic inside, it could take up to 4 seconds
47
47
// to determine whether or not the file path supplied is a Unix domain socket
48
48
func IsUnixDomainSocket (filePath string ) (bool , error ) {
49
- // Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
50
- // we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
51
-
52
49
// Note that querrying for the Reparse Points (https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-points)
53
50
// for the file (using FSCTL_GET_REPARSE_POINT) and checking for reparse tag: reparseTagSocket
54
51
// does NOT work in 1809 if the socket file is created within a bind mounted directory by a container
55
52
// and the FSCTL is issued in the host by the kubelet.
56
53
57
54
// If the file does not exist, it cannot be a Unix domain socket.
58
- if _ , err := os .Stat (filePath ); os .IsNotExist (err ) {
55
+ if info , err := os .Stat (filePath ); os .IsNotExist (err ) {
59
56
return false , fmt .Errorf ("File %s not found. Err: %v" , filePath , err )
57
+ } else if err == nil && info .Mode ()& os .ModeSocket != 0 { // Use os.ModeSocket (introduced in Go 1.23 on Windows)
58
+ klog .V (6 ).InfoS ("File identified as a Unix domain socket" , "filePath" , filePath )
59
+ return true , nil
60
60
}
61
-
62
61
klog .V (6 ).InfoS ("Function IsUnixDomainSocket starts" , "filePath" , filePath )
62
+ // Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
63
+ // we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
63
64
// As detailed in https://github.com/kubernetes/kubernetes/issues/104584 we cannot rely
64
65
// on the Unix Domain socket working on the very first try, hence the potential need to
65
66
// dial multiple times
0 commit comments