From 3b0a2adf296791bdbd0c1b0fba6399910c1fac82 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 17 Aug 2025 04:08:24 +0800 Subject: Context fixes --- forged/internal/incoming/lmtp/config.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'forged/internal/incoming/lmtp') diff --git a/forged/internal/incoming/lmtp/config.go b/forged/internal/incoming/lmtp/config.go index e6db5a6..c622648 100644 --- a/forged/internal/incoming/lmtp/config.go +++ b/forged/internal/incoming/lmtp/config.go @@ -1,6 +1,7 @@ package lmtp import ( + "context" "fmt" "net" @@ -33,11 +34,20 @@ func New(config Config) (server *Server) { } } -func (server *Server) Run() error { +func (server *Server) Run(ctx context.Context) error { listener, _, err := misc.ListenUnixSocket(server.socket) if err != nil { return fmt.Errorf("listen unix socket for LMTP: %w", err) } + defer func() { + _ = listener.Close() + }() + + go func() { + <-ctx.Done() + _ = listener.Close() + // TODO: Log the error + }() for { conn, err := listener.Accept() -- cgit v1.2.3