Commit 5683cc4
Make Abort() interrupt the libcurl and NSURLSession transports (#34)
Makes `UrlRequest::Abort()` actually interrupt the **libcurl** and
**NSURLSession** transports. Today `Abort()` cancels
`m_cancellationSource`, but only the Windows backend observes it (its
WinRT continuations are guarded by `.then(m_cancellationSource)`); the
curl and NSURLSession backends ignore it, so an in-flight request blocks
until the transport's own timeout and a consumer's cancellation can't
actually stop the work. Flagged as a follow-up in #31.
It's the transport-side prerequisite for fetch `AbortSignal` support in
JsRuntimeHost (BabylonJS/JsRuntimeHost#196): the polyfill there wires
`init.signal` to `UrlRequest::Abort()`, which currently no-ops on
Linux/Apple.
### Changes
- **libcurl**: drive the transfer through the **multi** interface
(`curl_multi_perform` + `curl_multi_poll` with a bounded 100 ms timeout)
instead of `curl_easy_perform`, re-checking `m_cancellationSource` each
iteration. `curl_easy_perform` blocks in an internal poll that, against
a peer which accepts but never responds, can wait indefinitely without
invoking any callback; the bounded poll bounds abort latency to ~100 ms
regardless of peer activity. A cancelled transfer reports
`CURLE_ABORTED_BY_CALLBACK`.
- **NSURLSession**: register a cancellation listener that `[task
cancel]`s the in-flight data task; its completion handler then fires
with `NSURLErrorCancelled`. The task is captured weakly (no retention
past completion; a late `Abort()` no-ops) and the ticket is `emplace()`d
because `arcana::cancellation::ticket` is a move-only `final_action`.
- **Test**: `AbortInterruptsInFlightRequest`, backed by an
offline-deterministic `HangingServer` (a loopback listener that accepts
but never responds). Skipped on the Windows backend, which observes
`Abort()` but doesn't populate the transport-error accessors.
### Validation
Built and ran `UrlLibTests` on **Win32 / macOS / Linux (gcc + clang)**
via a fork CI mirror (this branch combined with #32's workflows) — **all
four jobs green**. The abort test runs and passes in **301 ms** on
Ubuntu (curl) and exercises `NSURLErrorCancelled` on macOS
(NSURLSession):
```
[ RUN ] UrlRequestErrorReporting.AbortInterruptsInFlightRequest
[ OK ] UrlRequestErrorReporting.AbortInterruptsInFlightRequest (301 ms)
[ PASSED ] 7 tests.
```
This validation caught and fixed two bugs that Win32-only building had
hidden: a macOS-only compile error (`std::optional<ticket>::operator=`
on a move-only `final_action` → `emplace()`), and a Linux hang (the
original progress-callback abort blocked against an idle peer → reworked
to the multi interface; the `HangingServer` fixture also deadlocked its
own teardown because `close()` doesn't wake a blocked `accept()` on
Linux → `shutdown()` first).
UrlLib `main` has no CI yet (the workflows are in #32, still open), so
this PR doesn't get automated in-repo runs — the fork mirror is the
evidence until #32 lands.
### Scope / follow-ups
- `AbortSignal.timeout()` and the JSC/JSI rejection trackers are
unrelated JsRuntimeHost follow-ups.
Related: #31, #32, BabylonJS/JsRuntimeHost#196.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Branimir Karadžić (via Copilot) <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Gary Hsu <bghgary@users.noreply.github.com>1 parent 80293c0 commit 5683cc4
3 files changed
Lines changed: 228 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
231 | 248 | | |
232 | 249 | | |
233 | 250 | | |
| |||
244 | 261 | | |
245 | 262 | | |
246 | 263 | | |
| 264 | + | |
247 | 265 | | |
248 | 266 | | |
249 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
198 | | - | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
210 | 269 | | |
211 | 270 | | |
212 | 271 | | |
| |||
226 | 285 | | |
227 | 286 | | |
228 | 287 | | |
229 | | - | |
| 288 | + | |
230 | 289 | | |
231 | 290 | | |
232 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
53 | 62 | | |
54 | 63 | | |
55 | 64 | | |
| |||
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
76 | 92 | | |
77 | 93 | | |
78 | 94 | | |
| |||
186 | 202 | | |
187 | 203 | | |
188 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
189 | 295 | | |
190 | 296 | | |
191 | 297 | | |
| |||
352 | 458 | | |
353 | 459 | | |
354 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
355 | 503 | | |
356 | 504 | | |
357 | 505 | | |
| |||
0 commit comments