Skip to content

Commit

Permalink
changed the defer os remove
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverLok committed Aug 9, 2024
1 parent b4bd181 commit 8886705
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@ var AUTHENTICATION_NONCE = "nonce"
var socketPath = config.UNIX_SOCKET_PATH.Get()
var pidPath = config.PID_PATH.Get()

func cleanup() {
err := os.Remove(pidPath)
if err != nil {
log.Error("Failed to remove pid path.", err)
}

err = os.Remove(socketPath)
if err != nil {
log.Error("Failed to remove unix socket path.", err)
}
}

func StartServer() error {
defer cleanup()
var serverShutdown sync.WaitGroup

serverShutdown.Add(1)

go func() {
defer serverShutdown.Done()
defer os.Remove(pidPath)

err := startAPIServer()
if err != nil {
Expand All @@ -39,7 +51,6 @@ func StartServer() error {

go func() {
defer serverShutdown.Done()
defer os.Remove(socketPath)

err := startUnixServer()
if err != nil {
Expand Down

0 comments on commit 8886705

Please sign in to comment.