From fd0d63b103dfaf21d1c27363266590e723021c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 7 Feb 2026 17:30:34 +0100 Subject: [PATCH] fix: flush NATS buffer after sending completed response The CLI was reporting deployment failures even when the listener showed success. This was a race condition: after a successful switch deployment, the listener would send the "completed" response then immediately signal restart. The NATS connection closed before the buffered message was actually sent to the broker, so the CLI never received it. Adding Flush() after sending the completed response ensures the message reaches NATS before the listener can exit. Co-Authored-By: Claude Opus 4.5 --- cmd/homelab-deploy/main.go | 2 +- internal/listener/listener.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/homelab-deploy/main.go b/cmd/homelab-deploy/main.go index d01a8ed..71891a0 100644 --- a/cmd/homelab-deploy/main.go +++ b/cmd/homelab-deploy/main.go @@ -16,7 +16,7 @@ import ( "github.com/urfave/cli/v3" ) -const version = "0.1.9" +const version = "0.1.10" func main() { app := &cli.Command{ diff --git a/internal/listener/listener.go b/internal/listener/listener.go index 85be8ea..b30357f 100644 --- a/internal/listener/listener.go +++ b/internal/listener/listener.go @@ -260,6 +260,10 @@ func (l *Listener) handleDeployRequest(subject string, data []byte) { messages.StatusCompleted, "deployment completed successfully", )) + // Flush to ensure the completed response is sent before we potentially restart + if err := l.client.Flush(); err != nil { + l.logger.Error("failed to flush completed response", "error", err) + } if l.metrics != nil { l.metrics.RecordDeploymentEnd(req.Action, true, duration) }