From 0143a84cee1474ca4d9bc5e7dcb1ff5a1afff10c Mon Sep 17 00:00:00 2001 From: rouggy Date: Fri, 28 Aug 2026 08:43:06 +0200 Subject: [PATCH] fix(lotw): stop the heartbeat when the report starts arriving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deferred, it stopped at the end of the function — so 'still waiting for LoTW to build the report' kept printing between the megabyte lines, saying the opposite of what was happening. --- internal/extsvc/lotw.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/extsvc/lotw.go b/internal/extsvc/lotw.go index 4e8cc23..c1ce805 100644 --- a/internal/extsvc/lotw.go +++ b/internal/extsvc/lotw.go @@ -12,6 +12,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "syscall" "time" ) @@ -162,7 +163,11 @@ func DownloadLoTWConfirmations(ctx context.Context, client *http.Client, cfg Ser } } }() - defer close(beat) + // Stopped where the WAIT ends, not where the function does: deferred, the + // heartbeat went on counting between the megabyte lines and read as if the + // report were still being built while it was already arriving. + stopBeat := sync.OnceFunc(func() { close(beat) }) + defer stopBeat() var resp *http.Response for attempt := 1; ; attempt++ { @@ -192,6 +197,7 @@ func DownloadLoTWConfirmations(ctx context.Context, client *http.Client, cfg Ser return "", fmt.Errorf("lotw: request failed: %w", err) } defer resp.Body.Close() + stopBeat() say(note, fmt.Sprintf("LoTW answered (HTTP %d) — receiving…", resp.StatusCode)) body, err := readWithProgress(ctx, resp.Body, note) if err != nil {