Repository navigation
Conversation
… 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 GopeedLab#1563
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.
Grinv
force-pushed
the
fix/prefetch-stop-race
branch
from
October 24, 2026 06:38
51362f3 to
19e35e6
Compare
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1563.
stopPrefetchAndCopyDatawaited at most 10 s for the prefetch goroutine, but a stalled read only times out afterreadTimeout(15 s). After the wait gave up,cleanupPrefetchFileremoved the temp file whileasyncPrefetchcould still write to it.Changes:
stopPrefetch()closes the Resolve body to interrupt a pending read, then waits onprefetchExitCh.stopPrefetchAndCopyData,PauseandcompleteFromResolveFallbackall wait this way now.resolveRespLock, so a concurrentPauseandcommitResolveTakeovercan't close it twice.downloadWithProxycallsSetupbeforeResolve, as the downloader does. This fixes theTestFetcher_DownloadWithProxyreports.Tests:
TestFetcher_StopPrefetchUnblocksStalledReadpasses in about 0.05 s and fails after 15 s without the body close.go test -race ./internal/protocol/http/reports no races (12 on main) and takes about 180 s instead of 540 s.go test ./pkg/download/...passes.This may conflict with #1597 (
TimeoutReader).