aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/hooks/hooks.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-17 04:08:24 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-17 04:08:24 +0800
commit3b0a2adf296791bdbd0c1b0fba6399910c1fac82 (patch)
tree0725ce585922a47a86e58f5961df3571a2c3b6c1 /forged/internal/incoming/hooks/hooks.go
parentAdd some stubs (diff)
downloadforge-3b0a2adf296791bdbd0c1b0fba6399910c1fac82.tar.gz
forge-3b0a2adf296791bdbd0c1b0fba6399910c1fac82.tar.zst
forge-3b0a2adf296791bdbd0c1b0fba6399910c1fac82.zip
Context fixes
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)
}