fix(lotw): stop the heartbeat when the report starts arriving
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.
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"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
|
var resp *http.Response
|
||||||
for attempt := 1; ; attempt++ {
|
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)
|
return "", fmt.Errorf("lotw: request failed: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
stopBeat()
|
||||||
say(note, fmt.Sprintf("LoTW answered (HTTP %d) — receiving…", resp.StatusCode))
|
say(note, fmt.Sprintf("LoTW answered (HTTP %d) — receiving…", resp.StatusCode))
|
||||||
body, err := readWithProgress(ctx, resp.Body, note)
|
body, err := readWithProgress(ctx, resp.Body, note)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user