Commit 4baa44e
committed
Fix data race on SessionDataTask.started and tighten concurrency tests
started was written by resume() without synchronization while
ImageDownloader.startDownloadTask reads it from other threads — the
same class of race as the forceCancel one fixed in #2539. Guard it
with the existing lock, making resume() an atomic check-and-set with
task.resume() called outside the lock.
Also condense the forceCancel comment introduced in #2539 and add a
single combined stress test hammering all mutating and reading
surfaces of SessionDataTask concurrently (addCallback, forceCancel,
resume, started, containsCallbacks, didReceiveData, mutableDataCount,
completeAndRemoveAllCallbacks). Like the #2539 regression test, it is
meaningful mainly under Thread Sanitizer:
xcodebuild test -project Kingfisher.xcodeproj -scheme Kingfisher \
-destination 'platform=macOS' -enableThreadSanitizer YES \
-only-testing:KingfisherTests/ImageDownloaderTests/testSessionDataTaskConcurrentAccessIsThreadSafe1 parent 6207a84 commit 4baa44e
2 files changed
Lines changed: 50 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
143 | 149 | | |
144 | 150 | | |
145 | 151 | | |
146 | | - | |
147 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
148 | 160 | | |
149 | 161 | | |
150 | 162 | | |
| |||
156 | 168 | | |
157 | 169 | | |
158 | 170 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
169 | 174 | | |
170 | 175 | | |
171 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
429 | 461 | | |
430 | 462 | | |
431 | 463 | | |
| |||
0 commit comments