Attempt to delete socket file before listening on the path
This commit is contained in:
parent
4f6a89ced0
commit
5138ed7c6a
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"isle/daemon"
|
||||
"isle/daemon/jsonrpc2"
|
||||
"net"
|
||||
@ -22,11 +23,20 @@ func newHTTPServer(
|
||||
*http.Server, error,
|
||||
) {
|
||||
socketPath := daemon.HTTPSocketPath()
|
||||
ctx = mctx.Annotate(ctx, "socketPath", socketPath)
|
||||
|
||||
if err := os.Remove(socketPath); errors.Is(err, fs.ErrNotExist) {
|
||||
// No problem
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"removing %q prior to listening: %w", socketPath, err,
|
||||
)
|
||||
} else {
|
||||
logger.WarnString(
|
||||
ctx, "Deleted existing socket file prior to listening, it's possible a previous daemon failed to shutdown gracefully",
|
||||
)
|
||||
}
|
||||
|
||||
// TODO I restarted isle once and when it came back up it errored here
|
||||
// because the socket file already existed. isle should delete the file
|
||||
// during shutdown, but it should also check if the file exists on startup
|
||||
// in case shutdown wasn't clean.
|
||||
l, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
@ -40,7 +50,6 @@ func newHTTPServer(
|
||||
)
|
||||
}
|
||||
|
||||
ctx = mctx.Annotate(ctx, "httpAddr", l.Addr().String())
|
||||
logger.Info(ctx, "HTTP server socket created")
|
||||
|
||||
rpcHandler := jsonrpc2.Chain(
|
||||
|
Loading…
Reference in New Issue
Block a user