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 {