diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index fe57f23811..aa9a879792 100644 --- a/ecosystem/cache/server.go +++ b/ecosystem/cache/server.go @@ -8,6 +8,7 @@ import ( "os" "os/signal" "strings" + "syscall" "time" "github.com/lavanet/lava/protocol/chainlib/chainproxy" @@ -85,15 +86,28 @@ func (cs *CacheServer) Serve(ctx context.Context, var lis net.Listener var err error if strings.HasPrefix(listenAddr, unixPrefix) { // Unix socket - socketPath := strings.TrimPrefix(listenAddr, unixPrefix) - lis, err = net.Listen("unix", socketPath) + host, port, err := net.SplitHostPort(listenAddr) if err != nil { - utils.LavaFormatFatal("Cache server failure setting up Unix socket listener: %v\n", err) + utils.LavaFormatFatal("Failed to parse unix socket, provide address in this format unix:/tmp/example.sock: %v\n", err) + return + } + + syscall.Unlink(port) + + addr, err := net.ResolveUnixAddr(host, port) + if err != nil { + utils.LavaFormatFatal("Failed to resolve unix socket address: %v\n", err) + return + } + + lis, err = net.ListenUnix(host, addr) + if err != nil { + utils.LavaFormatFatal("Faild to listen to unix socket listener: %v\n", err) return } // Set permissions for the Unix socket - err := os.Chmod(socketPath, 0o600) + err = os.Chmod(port, 0o600) if err != nil { utils.LavaFormatFatal("Failed to set permissions for Unix socket: %v\n", err) return