Skip to content

Commit

Permalink
fix: unlink cache unix socket (lavanet#1435)
Browse files Browse the repository at this point in the history
* unlinking unix socket

* update unix listen creation

* to

* lint

* log

---------

Co-authored-by: amitz <[email protected]>
Co-authored-by: Amit Zafran <[email protected]>
  • Loading branch information
3 people authored May 13, 2024
1 parent 367d167 commit 9fb3f9b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions ecosystem/cache/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"strings"
"syscall"
"time"

"github.com/lavanet/lava/protocol/chainlib/chainproxy"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9fb3f9b

Please sign in to comment.