From 43f094e877c317154f79a85935390b587e976a34 Mon Sep 17 00:00:00 2001 From: amitz Date: Mon, 13 May 2024 00:26:32 +0300 Subject: [PATCH 1/5] unlinking unix socket --- ecosystem/cache/server.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index fe57f23811..cfce073db2 100644 --- a/ecosystem/cache/server.go +++ b/ecosystem/cache/server.go @@ -86,12 +86,21 @@ func (cs *CacheServer) Serve(ctx context.Context, var err error if strings.HasPrefix(listenAddr, unixPrefix) { // Unix socket socketPath := strings.TrimPrefix(listenAddr, unixPrefix) + + // err = syscall.Unlink(socketPath) + // if err != nil { + // // not really important if it fails + // utils.LavaFormatFatal("Unlink()", err) + // } + lis, err = net.Listen("unix", socketPath) if err != nil { utils.LavaFormatFatal("Cache server failure setting up Unix socket listener: %v\n", err) return } + defer lis.Close() + // Set permissions for the Unix socket err := os.Chmod(socketPath, 0o600) if err != nil { From a64bf9f84e20dba6a877317e4f96daf85f643f0a Mon Sep 17 00:00:00 2001 From: Amit Zafran Date: Mon, 13 May 2024 00:57:57 +0300 Subject: [PATCH 2/5] update unix listen creation --- ecosystem/cache/server.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index cfce073db2..a46f796a33 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,24 +86,29 @@ 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) - // err = syscall.Unlink(socketPath) - // if err != nil { - // // not really important if it fails - // utils.LavaFormatFatal("Unlink()", err) - // } + host, port, err := net.SplitHostPort(listenAddr) + if err != nil { + utils.LavaFormatFatal("Failed parse Unix socket: %v\n", err) + return + } + + syscall.Unlink(port) - lis, err = net.Listen("unix", socketPath) + addr, err := net.ResolveUnixAddr(host, port) if err != nil { - utils.LavaFormatFatal("Cache server failure setting up Unix socket listener: %v\n", err) + utils.LavaFormatFatal("Failed to resolve unix socket address: %v\n", err) return } - defer lis.Close() + 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 From 72c1c6c34cbb7f3e0848c8973549857fa83fd45c Mon Sep 17 00:00:00 2001 From: Amit Zafran Date: Mon, 13 May 2024 01:21:46 +0300 Subject: [PATCH 3/5] to --- ecosystem/cache/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index a46f796a33..aae740dce5 100644 --- a/ecosystem/cache/server.go +++ b/ecosystem/cache/server.go @@ -89,7 +89,7 @@ func (cs *CacheServer) Serve(ctx context.Context, host, port, err := net.SplitHostPort(listenAddr) if err != nil { - utils.LavaFormatFatal("Failed parse Unix socket: %v\n", err) + utils.LavaFormatFatal("Failed to parse Unix socket: %v\n", err) return } From 3e4f397b21009a0f01be413721e45848aef86df5 Mon Sep 17 00:00:00 2001 From: Amit Zafran Date: Mon, 13 May 2024 01:36:48 +0300 Subject: [PATCH 4/5] lint --- ecosystem/cache/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index aae740dce5..a81aacebd4 100644 --- a/ecosystem/cache/server.go +++ b/ecosystem/cache/server.go @@ -86,7 +86,6 @@ func (cs *CacheServer) Serve(ctx context.Context, var lis net.Listener var err error if strings.HasPrefix(listenAddr, unixPrefix) { // Unix socket - host, port, err := net.SplitHostPort(listenAddr) if err != nil { utils.LavaFormatFatal("Failed to parse Unix socket: %v\n", err) From 8d28279fa110b746b4709e2600ee6577990a72ed Mon Sep 17 00:00:00 2001 From: Amit Zafran Date: Mon, 13 May 2024 01:44:57 +0300 Subject: [PATCH 5/5] log --- ecosystem/cache/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecosystem/cache/server.go b/ecosystem/cache/server.go index a81aacebd4..aa9a879792 100644 --- a/ecosystem/cache/server.go +++ b/ecosystem/cache/server.go @@ -88,7 +88,7 @@ func (cs *CacheServer) Serve(ctx context.Context, if strings.HasPrefix(listenAddr, unixPrefix) { // Unix socket host, port, err := net.SplitHostPort(listenAddr) if err != nil { - utils.LavaFormatFatal("Failed to parse Unix socket: %v\n", err) + utils.LavaFormatFatal("Failed to parse unix socket, provide address in this format unix:/tmp/example.sock: %v\n", err) return }