aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/hooks/hooks.go
diff options
context:
space:
mode:
Diffstat (limited to 'forged/internal/incoming/hooks/hooks.go')
-rw-r--r--forged/internal/incoming/hooks/hooks.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/forged/internal/incoming/hooks/hooks.go b/forged/internal/incoming/hooks/hooks.go
index 18b9742..c021406 100644
--- a/forged/internal/incoming/hooks/hooks.go
+++ b/forged/internal/incoming/hooks/hooks.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "context"
"fmt"
"net"
@@ -40,15 +41,25 @@ func New(config Config) (server *Server) {
}
}
-func (server *Server) Run() error {
+func (server *Server) Run(ctx context.Context) error {
listener, _, err := misc.ListenUnixSocket(server.socketPath)
if err != nil {
return fmt.Errorf("listen unix socket for hooks: %w", err)
}
+ defer func() {
+ _ = listener.Close()
+ }()
+
+ go func() {
+ <-ctx.Done()
+ _ = listener.Close()
+ // TODO: Log the error
+ }()
for {
conn, err := listener.Accept()
if err != nil {
+ // TODO: Handle errors caused by context cancel
return fmt.Errorf("accept conn: %w", err)
}