From fdee28a81276d58a1fcfca0b8e0c9eaab9f65147 Mon Sep 17 00:00:00 2001 From: Ian Roberts Date: Sat, 19 Oct 2024 16:55:39 +0100 Subject: [PATCH] fix: clean up Unix socket file before exit If webhook is restarted with the same settings but the socket file has not been deleted, webhook will be unable to bind and will exit with an error. --- signals.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/signals.go b/signals.go index 23f0a74..9390513 100644 --- a/signals.go +++ b/signals.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package main @@ -6,6 +7,7 @@ import ( "log" "os" "os/signal" + "strings" "syscall" ) @@ -43,6 +45,15 @@ func watchForSignals() { log.Print(err) } } + if socket != "" && !strings.HasPrefix(socket, "@") { + // we've been listening on a named Unix socket, delete it + // before we exit so subsequent runs can re-bind the same + // socket path + err := os.Remove(socket) + if err != nil { + log.Printf("Failed to remove socket file %s: %v", socket, err) + } + } os.Exit(0) default: