nexora 0.0.1

Single-threaded io_uring HTTP/1.1, HTTP/2, WebSocket, and TLS proactor client and server SDK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
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
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
mod support;

use std::{
    cell::{Cell, RefCell},
    net::Ipv4Addr,
    rc::Rc,
    time::Duration,
};

use nexora::{
    Error, Headers, HttpClient, HttpServer, OriginKey, Request, WebSocketClient,
    WebSocketCloseCode, WebSocketCloseFrame, proto::Scheme,
};
use support::{
    DnsPlan, Gate, GateMode, IntoCheck, MockDns, Slot, TestResult, WebSocketEcho, check,
    client_config, drive_until, proactor, server_config, websocket_config,
};

fn url(port: u16, path: &str) -> String {
    format!("http://127.0.0.1:{port}{path}")
}

fn spin(
    ring: &mut nexora::Proactor,
    server: &mut HttpServer<Gate>,
    client: &mut HttpClient,
    ready: impl Fn() -> bool,
    budget: Duration,
) -> nexora::Result<bool> {
    drive_until(
        ring,
        |ring| {
            server.drive(ring)?;
            client.drive_with(ring, &mut *server)?;
            Ok(ready())
        },
        budget,
    )
}

#[test]
fn lc_01_cancel_is_exactly_once_across_dns_queue_and_active_exchange() -> TestResult {
    let _exclusive = support::exclusive();
    let dns = MockDns::spawn(
        DnsPlan::answer(vec![Ipv4Addr::LOCALHOST]).delay(Duration::from_millis(350)),
    )
    .t()?;
    let mut ring = proactor().t()?;
    let gate = Gate::new(GateMode::Echo);
    let held = gate.held();
    let mut server =
        HttpServer::bind(&mut ring, support::ephemeral(), server_config(3).t()?, gate).t()?;
    let port = server.local_addr().port();
    let mut config = client_config(1, 2).t()?;
    config.dns_servers_csv = Some(dns.servers_csv());
    let mut client = HttpClient::new(&mut ring, config).t()?;
    let outcomes = Rc::new(RefCell::new(Vec::new()));
    let mut ids = Vec::new();
    for index in 0..4 {
        let outcomes = Rc::clone(&outcomes);
        let request = Request::get(&format!("http://wait.test:{port}/echo")).t()?;
        let id = client
            .submit(&mut ring, request, move |_ctx, id, result| {
                outcomes.borrow_mut().push((id.raw(), result.is_err()));
            })
            .t()?;
        ids.push((index, id));
    }
    let started = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            client.drive_with(ring, &mut server)?;
            Ok(dns.udp_queries() > 0)
        },
        Duration::from_millis(200),
    )
    .t()?;
    check(started, "dns query did not start").t()?;
    check(client.cancel(&mut ring, ids[0].1), "first waiter cancels").t()?;
    check(
        !client.cancel(&mut ring, ids[0].1),
        "second cancel is terminal",
    )
    .t()?;
    let done = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            client.drive_with(ring, &mut server)?;
            Ok(outcomes.borrow().len() == 4)
        },
        Duration::from_secs(3),
    )
    .t()?;
    check(done, "dns waiters did not finish").t()?;
    let cancelled = outcomes
        .borrow()
        .iter()
        .filter(|(id, failed)| *id == ids[0].1.raw() && *failed)
        .count();
    check(cancelled == 1, "cancelled waiter fires once").t()?;
    check(
        outcomes
            .borrow()
            .iter()
            .filter(|(_, failed)| !failed)
            .count()
            == 3,
        "the other dns waiters complete",
    )
    .t()?;

    client.shutdown_with(&mut ring, &mut server).t()?;
    let mut config = client_config(4, 5).t()?;
    config.dns_servers_csv = Some(dns.servers_csv());
    config.pool.max_connections_per_origin = 1;
    let mut limited = HttpClient::new(&mut ring, config).t()?;
    let queued = Rc::new(Cell::new(0u32));
    let hold_queued = Rc::clone(&queued);
    limited
        .submit(
            &mut ring,
            Request::get(&url(port, "/hold")).t()?,
            move |_ctx, _id, result| {
                if matches!(result, Err(Error::Cancelled)) {
                    hold_queued.set(hold_queued.get().saturating_add(1));
                } else {
                    hold_queued.set(hold_queued.get().saturating_add(10));
                }
            },
        )
        .t()?;
    let parked = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            limited.drive_with(ring, &mut server)?;
            Ok(held.borrow().is_some())
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(parked, "active exchange was not held").t()?;
    let echo_queued = Rc::clone(&queued);
    let echo_id = limited
        .submit(
            &mut ring,
            Request::get(&url(port, "/echo")).t()?,
            move |_ctx, _id, result| {
                if matches!(result, Err(Error::Cancelled)) {
                    echo_queued.set(echo_queued.get().saturating_add(1));
                } else {
                    echo_queued.set(echo_queued.get().saturating_add(10));
                }
            },
        )
        .t()?;
    check(limited.cancel(&mut ring, echo_id), "queued request cancels").t()?;
    let settled = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            limited.drive_with(ring, &mut server)?;
            Ok(queued.get() > 0)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(settled && queued.get() == 1, "queued cancel callback once").t()?;
    if let Some(responder) = held.borrow_mut().take() {
        responder
            .respond(nexora::Response::text(nexora::StatusCode::OK, "late"))
            .t()?;
    }
    client.shutdown_with(&mut ring, &mut server).t()?;
    drop(client);
    limited.shutdown_with(&mut ring, &mut server).t()?;
    let mut last_config = client_config(6, 7).t()?;
    last_config.dns_servers_csv = Some(dns.servers_csv());
    let mut last = HttpClient::new(&mut ring, last_config).t()?;
    let last_hits = Rc::new(Cell::new(0u32));
    let mut last_ids = Vec::new();
    let baseline = dns.udp_queries();
    for _ in 0..2 {
        let last_hits = Rc::clone(&last_hits);
        let id = last
            .submit(
                &mut ring,
                Request::get(&format!("http://wait.test:{port}/echo")).t()?,
                move |_ctx, _id, result| {
                    if matches!(result, Err(Error::Cancelled)) {
                        last_hits.set(last_hits.get().saturating_add(1));
                    } else {
                        last_hits.set(last_hits.get().saturating_add(10));
                    }
                },
            )
            .t()?;
        last_ids.push(id);
    }
    let sent = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            last.drive_with(ring, &mut server)?;
            Ok(dns.udp_queries() > baseline)
        },
        Duration::from_millis(400),
    )
    .t()?;
    check(sent, "shared dns query was not sent").t()?;
    check(
        last.cancel(&mut ring, last_ids[0]),
        "first of the pair cancels",
    )
    .t()?;
    check(last.cancel(&mut ring, last_ids[1]), "last waiter cancels").t()?;
    let both = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            last.drive_with(ring, &mut server)?;
            Ok(last_hits.get() >= 2)
        },
        Duration::from_millis(400),
    )
    .t()?;
    check(both && last_hits.get() == 2, "each waiter fires once").t()?;
    let held_queries = dns.udp_queries();
    let released = Rc::new(Cell::new(false));
    let released_done = Rc::clone(&released);
    last.submit(
        &mut ring,
        Request::get(&format!("http://wait.test:{port}/echo")).t()?,
        move |_ctx, _id, result| released_done.set(result.is_ok()),
    )
    .t()?;
    let retried = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            last.drive_with(ring, &mut server)?;
            Ok(dns.udp_queries() > held_queries)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(retried, "last waiter cancel did not release the query").t()?;
    drop(server);
    Ok(())
}

#[test]
fn lc_02_cancel_then_follow_up_survives_both_completions() -> TestResult {
    let _exclusive = support::exclusive();
    let mut ring = proactor().t()?;
    let gate = Gate::new(GateMode::Echo);
    let held = gate.held();
    let mut server =
        HttpServer::bind(&mut ring, support::ephemeral(), server_config(3).t()?, gate).t()?;
    let port = server.local_addr().port();
    let mut client = HttpClient::new(&mut ring, client_config(1, 2).t()?).t()?;
    let slot = Slot::new();
    let done = slot.clone();
    let id = client
        .submit(
            &mut ring,
            Request::get(&url(port, "/hold")).t()?,
            move |_ctx, _id, result| done.set(matches!(result, Err(Error::Cancelled))),
        )
        .t()?;
    let parked = spin(
        &mut ring,
        &mut server,
        &mut client,
        || held.borrow().is_some(),
        Duration::from_secs(2),
    )
    .t()?;
    check(parked, "in-flight request was not accepted").t()?;
    check(client.cancel(&mut ring, id), "in-flight cancel").t()?;
    let cancelled = spin(
        &mut ring,
        &mut server,
        &mut client,
        || slot.calls() == 1,
        Duration::from_secs(2),
    )
    .t()?;
    check(
        cancelled && slot.take() == Some(true),
        "cancel callback once",
    )
    .t()?;
    let follow = Slot::new();
    let follow_done = follow.clone();
    client
        .submit(
            &mut ring,
            Request::get(&url(port, "/echo")).t()?,
            move |_ctx, _id, result| follow_done.set(result.is_ok()),
        )
        .t()?;
    let recovered = spin(
        &mut ring,
        &mut server,
        &mut client,
        || follow.calls() == 1,
        Duration::from_secs(2),
    )
    .t()?;
    check(
        recovered && follow.take() == Some(true),
        "follow-up succeeds",
    )
    .t()?;
    ring.shutdown().t()
}

#[test]
fn lc_03_responder_drop_is_500_and_late_respond_fails() -> TestResult {
    let _exclusive = support::exclusive();
    let mut ring = proactor().t()?;
    let gate = Gate::new(GateMode::Echo);
    let held = gate.held();
    let mut server =
        HttpServer::bind(&mut ring, support::ephemeral(), server_config(3).t()?, gate).t()?;
    let port = server.local_addr().port();
    let mut client = HttpClient::new(&mut ring, client_config(1, 2).t()?).t()?;
    let dropped = Slot::new();
    let dropped_done = dropped.clone();
    client
        .submit(
            &mut ring,
            Request::get(&url(port, "/drop")).t()?,
            move |_ctx, _id, result| {
                dropped_done.set(result.map(|response| response.status.as_u16()).t());
            },
        )
        .t()?;
    let saw_drop = spin(
        &mut ring,
        &mut server,
        &mut client,
        || dropped.calls() == 1,
        Duration::from_secs(2),
    )
    .t()?;
    check(saw_drop, "drop responder timed out").t()?;
    check(
        dropped
            .take()
            .ok_or_else(|| String::from("missing drop"))
            .t()?
            == Ok(500),
        "dropped responder becomes 500",
    )
    .t()?;
    let late = Slot::new();
    let late_done = late.clone();
    let id = client
        .submit(
            &mut ring,
            Request::get(&url(port, "/hold")).t()?,
            move |_ctx, _id, result| late_done.set(matches!(result, Err(Error::Cancelled))),
        )
        .t()?;
    let parked = spin(
        &mut ring,
        &mut server,
        &mut client,
        || held.borrow().is_some(),
        Duration::from_secs(2),
    )
    .t()?;
    check(parked, "responder was not parked").t()?;
    check(client.cancel(&mut ring, id), "disconnect the caller").t()?;
    let saw_close = spin(
        &mut ring,
        &mut server,
        &mut client,
        || {
            held.borrow()
                .as_ref()
                .is_some_and(nexora::Responder::is_closed)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(saw_close, "server did not observe the disconnect").t()?;
    let responder = held
        .borrow_mut()
        .take()
        .ok_or_else(|| String::from("missing responder"))
        .t()?;
    let respond_error = responder.respond(nexora::Response::text(nexora::StatusCode::OK, "late"));
    check(respond_error.is_err(), "respond after disconnect fails").t()?;
    let observed = spin(
        &mut ring,
        &mut server,
        &mut client,
        || late.calls() == 1,
        Duration::from_secs(2),
    )
    .t()?;
    check(
        observed && late.take() == Some(true),
        "caller observes cancellation",
    )
}

#[test]
fn lc_04_goaway_websocket_close_and_idle_eviction() -> TestResult {
    let _exclusive = support::exclusive();
    let mut ring = proactor().t()?;
    let mut config = client_config(1, 2).t()?;
    config.pool.idle_timeout = Duration::from_millis(40);
    config.pool.max_idle_per_origin = 1;
    let gate = Gate::new(GateMode::Echo);
    let held = gate.held();
    let mut server =
        HttpServer::bind(&mut ring, support::ephemeral(), server_config(3).t()?, gate).t()?;
    let port = server.local_addr().port();
    let mut client = HttpClient::new(&mut ring, config).t()?;
    let slot = Slot::new();
    let done = slot.clone();
    client
        .submit(
            &mut ring,
            Request::get(&url(port, "/echo")).t()?,
            move |_ctx, _id, result| done.set(result.is_ok()),
        )
        .t()?;
    let ok = spin(
        &mut ring,
        &mut server,
        &mut client,
        || slot.calls() == 1,
        Duration::from_secs(2),
    )
    .t()?;
    check(ok, "warmup request").t()?;
    let origin = OriginKey::new(Scheme::Http, "127.0.0.1", port);
    let evicted = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            client.drive_with(ring, &mut server)?;
            Ok(client.idle_connection_count(&origin) == 0)
        },
        Duration::from_secs(1),
    )
    .t()?;
    check(evicted, "idle connection was not evicted").t()?;
    client.shutdown_with(&mut ring, &mut server).t()?;
    drop(client);
    let mut http2_config = client_config(7, 8).t()?;
    http2_config.http2_prior_knowledge = true;
    http2_config.prefer_http2 = true;
    let mut http2 = HttpClient::new(&mut ring, http2_config).t()?;
    let primed = Slot::new();
    let primed_done = primed.clone();
    http2
        .submit(
            &mut ring,
            Request::get(&url(port, "/hold")).t()?,
            move |_ctx, _id, result| primed_done.set(result.is_ok()),
        )
        .t()?;
    let parked = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            http2.drive_with(ring, &mut server)?;
            Ok(held.borrow().is_some())
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(parked, "http2 exchange was not held").t()?;
    server.initiate_graceful_shutdown(&mut ring).t()?;
    let responder = held
        .borrow_mut()
        .take()
        .ok_or_else(|| String::from("missing goaway responder"))
        .t()?;
    responder
        .respond(nexora::Response::text(nexora::StatusCode::OK, "late"))
        .t()?;
    let migrated = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            http2.drive_with(ring, &mut server)?;
            Ok(primed.calls() == 1)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(
        migrated && primed.take() == Some(true),
        "in-flight request survived goaway",
    )
    .t()?;
    http2.shutdown_with(&mut ring, &mut server).t()?;
    drop(http2);

    let echo = WebSocketEcho::new();
    let mut websocket_server = HttpServer::bind(
        &mut ring,
        support::ephemeral(),
        server_config(6).t()?,
        Gate::new(GateMode::Echo),
    )
    .t()?
    .with_websocket_handler("/stream", echo);
    let websocket_port = websocket_server.local_addr().port();
    let mut websocket = WebSocketClient::new(&mut ring, websocket_config(4, 5).t()?).t()?;
    let events = Rc::new(RefCell::new(Vec::new()));
    let recorded = Rc::clone(&events);
    let session = websocket
        .connect(
            &mut ring,
            &format!("ws://127.0.0.1:{websocket_port}/stream"),
            Headers::new(),
            move |_ctx, _id, result| {
                if result.is_ok() {
                    recorded.borrow_mut().push(1u8);
                }
            },
        )
        .t()?;
    let opened = drive_until(
        &mut ring,
        |ring| {
            websocket_server.drive(ring)?;
            websocket.drive_with(
                ring,
                &mut nexora::CompletionRoutes::new(&mut websocket_server, &mut server),
            )?;
            Ok(events.borrow().contains(&1))
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(opened, "websocket did not open").t()?;
    websocket
        .close(
            &mut ring,
            session,
            Some(WebSocketCloseFrame {
                code: WebSocketCloseCode::Normal,
                reason: "done".into(),
            }),
        )
        .t()?;
    let closed = drive_until(
        &mut ring,
        |ring| {
            websocket_server.drive(ring)?;
            websocket.drive_with(
                ring,
                &mut nexora::CompletionRoutes::new(&mut websocket_server, &mut server),
            )?;
            Ok(!websocket.is_open(session) && websocket.active_session_count() == 0)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(closed, "websocket close was not observed")
}

#[test]
fn lc_05_dropped_client_does_not_block_a_sibling_subsystem() -> TestResult {
    let _exclusive = support::exclusive();
    let mut ring = proactor().t()?;
    let mut server = HttpServer::bind(
        &mut ring,
        support::ephemeral(),
        server_config(3).t()?,
        Gate::new(GateMode::Echo),
    )
    .t()?;
    let port = server.local_addr().port();
    let mut doomed = HttpClient::new(&mut ring, client_config(1, 2).t()?).t()?;
    let fired = Rc::new(Cell::new(false));
    let flag = Rc::clone(&fired);
    doomed
        .submit(
            &mut ring,
            Request::get(&url(port, "/hold")).t()?,
            move |_ctx, _id, _result| flag.set(true),
        )
        .t()?;
    let _ = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            doomed.drive_with(ring, &mut server)?;
            Ok(false)
        },
        Duration::from_millis(30),
    )
    .t()?;
    drop(doomed);
    let mut sibling = HttpClient::new(&mut ring, client_config(4, 5).t()?).t()?;
    let slot = Slot::new();
    let done = slot.clone();
    sibling
        .submit(
            &mut ring,
            Request::get(&url(port, "/echo")).t()?,
            move |_ctx, _id, result| done.set(result.is_ok()),
        )
        .t()?;
    let finished = drive_until(
        &mut ring,
        |ring| {
            server.drive(ring)?;
            sibling.drive_with(ring, &mut |completion: nexora::Completion,
                                            submissions: &mut nexora::SubmissionContext<
                '_,
            >| {
                if [1, 2].contains(&completion.operation_id.subsystem_id().raw()) {
                    // The dropped owner retains its DMA operands and suppresses callbacks.
                    submissions.claim_completion(completion)
                } else {
                    nexora::CompletionDispatcher::dispatch(&mut server, completion, submissions)
                }
            })?;
            Ok(slot.calls() == 1)
        },
        Duration::from_secs(2),
    )
    .t()?;
    check(
        finished && slot.take() == Some(true),
        "sibling client completes",
    )
    .t()?;
    check(!fired.get(), "dropped client callback stays silent").t()?;
    ring.shutdown().t()
}

#[test]
fn lc_06_many_requests_and_cancels_do_not_leak_descriptors() -> TestResult {
    let _exclusive = support::exclusive();
    let before_fd = support::open_fd_count().t()?;
    let before_threads = support::thread_count().t()?;
    let after_echo;
    {
        let mut ring = proactor().t()?;
        let mut server = HttpServer::bind(
            &mut ring,
            support::ephemeral(),
            server_config(3).t()?,
            Gate::new(GateMode::Echo),
        )
        .t()?;
        let port = server.local_addr().port();
        let mut client = HttpClient::new(&mut ring, client_config(1, 2).t()?).t()?;
        let mut steady = 0usize;
        for index in 0..1000 {
            let slot = Slot::new();
            let done = slot.clone();
            client
                .submit(
                    &mut ring,
                    Request::get(&url(port, "/echo")).t()?,
                    move |_ctx, _id, result| done.set(result.is_ok()),
                )
                .map_err(|error| format!("echo submit {index}: {error}"))?;
            let ok = spin(
                &mut ring,
                &mut server,
                &mut client,
                || slot.calls() == 1,
                Duration::from_secs(2),
            )
            .map_err(|error| format!("echo drive {index}: {error}"))?;
            check(
                ok && slot.take() == Some(true),
                format!("request failed inside the leak loop at {index}"),
            )?;
            if index == 0 {
                steady = support::open_fd_count().t()?;
            }
        }
        after_echo = support::open_fd_count().t()?;
        check(
            after_echo == steady,
            format!("echo cycle grew descriptors: steady {steady} after {after_echo}"),
        )?;
        for index in 0..100 {
            let slot = Slot::new();
            let done = slot.clone();
            let id = client
                .submit(
                    &mut ring,
                    Request::get(&url(port, "/hold")).t()?,
                    move |_ctx, _id, result| done.set(matches!(result, Err(Error::Cancelled))),
                )
                .map_err(|error| format!("cancel submit {index}: {error}"))?;
            check(client.cancel(&mut ring, id), format!("cancel {index}"))?;
            let ok = spin(
                &mut ring,
                &mut server,
                &mut client,
                || slot.calls() == 1,
                Duration::from_secs(2),
            )
            .map_err(|error| format!("cancel drive {index}: {error}"))?;
            check(ok, format!("cancel callback missing at {index}"))?;
        }
        let _settled = drive_until(
            &mut ring,
            |ring| {
                server.drive(ring)?;
                client.drive_with(ring, &mut server)?;
                Ok(false)
            },
            Duration::from_millis(50),
        )
        .map_err(|error| format!("cancel settle: {error}"))?;
        let after_cancel = support::open_fd_count().t()?;
        check(
            after_cancel == after_echo,
            format!("cancel cycle grew descriptors: echo {after_echo} cancel {after_cancel}"),
        )?;
        check(
            support::thread_count().t()? == before_threads,
            "thread count grew",
        )?;
        client.shutdown_with(&mut ring, &mut server).t()?;
        drop(client);
        drop(server);
    }
    let after_fd = support::open_fd_count().t()?;
    check(
        after_fd <= after_echo,
        format!("drop grew descriptors: live {after_echo} dropped {after_fd} baseline {before_fd}"),
    )
}