Commit c6577d7
committed
Fix internal/http/TestDownload_CancelDownload
The test's server handler used to loop on writes. Once the client
canceled the download, the next write hit a broken pipe and failed the
test intermittently:
- The handler kept looping: write chunk, check request context, short
sleep, repeat.
- When the test client canceled, the HTTP stack closed the TCP
connection immediately.
- The handler only noticed cancellation after the select ran, but there
was a race between the next write and the select.
- If Go scheduled the loop so that it hit another write before the
select observed the request context being done, that write ran against
a half-closed socket and returned broken pipe.
The handler now writes once, flushes to let the client see the written
data, waits for the request context being done, and asserts that the
request context was canceled, hence it will never write more than once.
Fixes: 1a54f6c ("Implement cancellation of stale downloads")
Signed-off-by: Tom Wieczorek <[email protected]>1 parent 453995a commit c6577d7
1 file changed
+17
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
79 | 78 | | |
80 | 79 | | |
81 | 80 | | |
| 81 | + | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
93 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
0 commit comments