unescapeHTMLEntities applied its replacements while ranging over a map,
so the order changed from run to run. An escaped ampersand such as
"a&lt;b.txt" came out as "a<b.txt" or, when & was replaced
first, as the double-decoded "a<b.txt".
Replace all entities in a single pass with strings.NewReplacer and
cover the escaped-ampersand cases in TestUnescapeHTMLEntities, running
each case repeatedly so an order-dependent implementation fails.
* fix(http): wait for the prefetch goroutine to exit before reusing its file
stopPrefetchAndCopyData waited at most 10 s for the Resolve prefetch, but a
stalled body read only times out after readTimeout (15 s). The caller then
closed and removed the temporary file while the prefetch goroutine could
still write to it.
Stopping the prefetch now closes the Resolve body, which interrupts a
pending read, and waits on a channel closed when the goroutine exits. Pause
uses the same path. The stop channel is closed under resolveRespLock so a
concurrent Pause and first-connection takeover cannot close it twice.
The proxy test helper now calls Setup before Resolve, as the downloader
does, so the Resolve request also goes through the proxy.
Fixes#1563
* refactor(http): wait on prefetchExitCh in completeFromResolveFallback
Replaces the 10 ms polling loop with the exit channel added in the
previous commit, so every place that waits for the prefetch uses it.
---------
Co-authored-by: Levi <[email protected]>
The prefetch goroutine sets prefetchDone only after one more read and
closing the body. A Start in that window took the whole file as the
fallback snapshot, expandConnections marked the task done, and the temp
file was never copied, leaving a zero-filled target.
Read prefetchSize once and treat the prefetch as complete when it reached
the known size.