rpc: try to remove socket if already exists (#89)

This commit is contained in:
Max 2025-12-05 16:14:40 +01:00 committed by GitHub
parent e994260bdb
commit df929520a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import (
"log"
"net"
"net/rpc"
"os"
"sync"
"syscall"
@ -178,6 +179,11 @@ func RpcServer(ctx context.Context, wg *sync.WaitGroup, ma multiaddr.Multiaddr,
var l net.Listener
oldUmask := syscall.Umask(0o007)
err = os.Remove(addr)
if err != nil && !os.IsNotExist(err) {
log.Fatal("[!] Could not remove old RPC socket: ", err)
}
var lc net.ListenConfig
l, err = lc.Listen(ctx, "unix", addr)
syscall.Umask(oldUmask)