Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c018d6dad | ||
|
|
c6de7842f7 |
No files matched your search
@@ -1,9 +1,9 @@
|
||||
# Workflow state
|
||||
|
||||
Updated: 2026-11-29.
|
||||
Updated: 2026-12-01.
|
||||
Repository: VoidLibrary; active branch `feat/roadmap-p2-wave11` (from `main` at `38436b1`;
|
||||
Waves 1–10 + `VL-001`..`VL-013` merged into `main` at `7d7d23e` and pushed to `origin/main`).
|
||||
Current wave: **Wave 11 — execution-path backfill** (see D-033..D-036 and `TASKS.md`).
|
||||
Waves 1–11 + `VL-001`..`VL-013` complete and merging into `main`, pushed to `origin/main`).
|
||||
Current wave: **Wave 11 — execution-path backfill COMPLETE**; next: **Wave 12 — VoidForge upstream requests (`D-041`) + `X-QA-01..04`**.
|
||||
|
||||
## Completed objective
|
||||
|
||||
@@ -363,30 +363,26 @@ while leaving local untracked files untouched.
|
||||
- Full Debug ASan+UBSan (`/tmp/void-w10-asan`, 55 modules, `-Werror`): `VoidTests` `1,484` discovered (`1,480 ✔`, `4 ⊘`, `0 ✘`) in `42.48s`, `0` leaks, `0` UB.
|
||||
- Debug TSan (`/tmp/void-w10-tsan`, `Discovery;DiscoveryRpc;Scheduler;SchedulerStorage;Messaging;MessagingStorage;MessagingRpc;System;Testing`, 23 modules, `-Werror`): `903` discovered (`900 ✔`, `3 ⊘`, `0 ✘`) in `23.20s`, `0` data races, `0` lock-order warnings.
|
||||
|
||||
### Wave 11 — Execution-path backfill (`feat/roadmap-p2-wave11`, in progress)
|
||||
### Wave 11 — Execution-path backfill (`feat/roadmap-p2-wave11`, verified & merged to `main`)
|
||||
|
||||
Checkpoint 2026-11-29 (branch pushed to `origin/feat/roadmap-p2-wave11`; `main` untouched at `38436b1`):
|
||||
- Baseline `38436b1` full RelWithDebInfo `-Werror` (`/tmp/void-w11-base`, 55 modules): 1,484 tests
|
||||
(1,480 ✔, 4 ⊘), `ctest` 2/2.
|
||||
- Planning: `tasks/W11-PLAN-OUTPUT.md` → PREFLIGHT 1 (CHANGES_REQUIRED, F1 P1 + F2–F13) →
|
||||
`tasks/W11-PLAN-REV1-OUTPUT.md` → PREFLIGHT 2 (CHANGES_REQUIRED, N1–N6) → `tasks/W11-CONTRACT-R2.md`
|
||||
→ spec review (S1–S9, A1–A3) adopted into specs (D-038, D-040, D-042).
|
||||
- Commits: `7f95f89` prep (error codes, area plans), `a8a9249`/`99203ce`/`c6789e7` docs/specs,
|
||||
`26edf65` M-FUNCTIONAL-03 (VERIFIED).
|
||||
- In flight: M-TIME-03 B1 TimerQueue diff applied UNCOMMITTED in the main checkout (root-verified:
|
||||
681 tests 678 ✔ 3 ⊘, TSan 28/28 ×3, ASan 468 ✔; fresh review pending); S-IO-03 (B2) implementer
|
||||
in an agent worktree. Specs ready: M-ASYNC-04 (A2, after B1 commit), M-TIME-03-B1b (`retry_async`,
|
||||
after B1 commit), M-ASYNC-05 (A3, after A2). Still to specify: S-IO-04 (A4), S-RUNTIME-02 (B3),
|
||||
S-RUNTIME-03 (B4).
|
||||
- Dispatch rule (X-WF-01): agent worktrees start at `main`; each prompt fast-forwards to the stated HEAD.
|
||||
- Note: a 5-hour usage limit interrupted two agents once; they were resumed with SendMessage.
|
||||
- **Planning & contracts (`7f95f89`, `a8a9249`, `99203ce`, `c6789e7`, `95785ed`, `4ea6384`, `7c1fd3c`, `09789ae`, `3ce21be`)**: `W11-PLAN-OUTPUT.md`, PREFLIGHT 1 & 2 (`W11-PLAN-REV1-OUTPUT.md`, `W11-CONTRACT-R2.md`), spec reviews (`D-038`, `D-040`, `D-042`), error code reservations, area plans (`Functional.md`, `Runtime.md`, `IO.md`, `MIGRATION.md`).
|
||||
- **Execution-path implementation**:
|
||||
- `M-FUNCTIONAL-03` (`26edf65`): pure retry policy state machine + `retry_blocking`.
|
||||
- `M-TIME-03` (`99a1100`, `5c24f8e`): injected-clock `TimerQueue` + saturation helpers + `retry_async`.
|
||||
- `M-ASYNC-04` (`b2c8411`): `ThreadExecutor`, `FuturePool`, `AsyncChannel`, bounded `parallel_for`, `Executor.hpp` `spawn()` race fix.
|
||||
- `S-IO-03` (`1e752da`): bounded positional `File` workers, sync, active-cancel, shutdown core, D1 retire-once fixes.
|
||||
- `M-ASYNC-05` (`ef85ce0`): `EventBus` injected/joined lifecycle + `Observable` reentrancy queue.
|
||||
- `S-IO-04` (`50029e1`): `Driver::run`, `Pump.hpp` `pump_until`, `SystemAsync` shutdown conformance.
|
||||
- `S-RUNTIME-02/03` (`7bea7df`): `Host` explicit start, readiness, reverse failed-start cleanup, phased shutdown (`Lifecycle.hpp`, `Detail/HostCore.hpp`, `Host.hpp`).
|
||||
- **Adversarial review & post-fix hardening (`c6de784`)**:
|
||||
- Fresh adversarial review (`925b2cd8-7c57-4121-b6c5-b925c6a434f6`) returned `CHANGES_REQUIRED` (1 P1 + 7 P2 + 1 P3) across `EventBus.hpp`, `Pump.hpp`, `Driver.hpp`, `EpollDriver.cpp`, and `HostCore.hpp`.
|
||||
- Resolved all 9 findings in `c6de784` with 10 regression tests (`EventBus::finish_entry_dispatch` + pumping `self_join`; `pump_until` / `Driver::run` / `run_reactor_loop` `steady_clock` idle pacing + `EpollBackend` `EPOLLIN` disarming; `MockBackend::try_acquire` shutdown/closing TOCTOU guard; `HostCore` `start_running`/mutex sync, `flushing_exporters` single-drain poll, embedded background-worker `shutdown_blocking`, and incomplete `stopping_io` worker count). Post-fix review: `READY`.
|
||||
- **Integrated post-fix verification (`c6de784`, `-DVOID_WARNINGS_AS_ERRORS=ON`)**:
|
||||
- Targeted TSan & Runtime (`verify_w11_fixes.sh` + `verify_runtime.sh`): `110/110 ✔` TSan (`599.1ms`), all 6 Runtime gates passed (`37/37 ✔`, `nosys` `ctest` `2/2`, TSan, ASan, zero `Void/System/` includes in `include/Void/Runtime/**`).
|
||||
- Full RelWithDebInfo (`/tmp/void-w11-full`, 55 modules): `VoidTests` `1,694` (`1,690 ✔`, `4 ⊘`, `0 ✘`) in `25.13s`; `ctest` `2/2` in `110.10s` (`VoidTests` `25.01s`, `VoidInstalledComponentConsumers` `85.09s` across all `41` consumers); `VoidFoundationBench` (`rev=c6de7842f732`, `/tmp/void-w11-full/post-w11.json`): `harness_empty_loop` `0.40ns`, `core_uuid_parse_hyphenated` `26.06ns`, `core_uuid_to_string` `18.06ns`, `core_hash_fnv1a64_256b` `186.38ns`, `core_hash_murmur3_256b` `69.57ns`, `functional_result_ok_chain` `1.16ns`, `functional_error_with_context` `61.13ns`, `math_checked_add_loop` `0.50ns`, `containers_spsc_ring_push_pop` `9.33ns`, `containers_lru_get_put` `22.02ns`, `binary_reader_u64_be` `1.19ns`, `data_json_parse_small_object` `302.08ns`, `data_json_serialize_small_object` `170.90ns`.
|
||||
- Full Debug ASan+UBSan (`/tmp/void-w11-asan`, 55 modules): `VoidTests` `1,694` (`1,690 ✔`, `4 ⊘`, `0 ✘`) in `67.61s`, `0` leaks, `0` UB.
|
||||
- Wave 11 Debug TSan (`/tmp/void-w11-tsan`, 21 modules): unfiltered `VoidTests` `1,035` (`1,032 ✔`, `3 ⊘`, `0 ✘`) in `34.78s`; 3x 169-test stress loop `169/169 ✔` (`2.12s`, `3.07s`, `2.14s`), `0` data races / lock-order warnings.
|
||||
|
||||
## Ownership and next step
|
||||
|
||||
Waves 1–10 (`P0`, `P1` except `M-FUNCTIONAL-03`/`M-TIME-03`, the P2 operations/storage/
|
||||
lifecycle/network modules, `VL-001`..`VL-013`, and P3 core subsystems `Discovery`,
|
||||
`Scheduler`, `Messaging`) are complete, verified, merged and pushed. A 2026-11-29 audit
|
||||
(D-033) found 2 P1 and 40 P2 roadmap tasks still open. **Wave 11** backfills the
|
||||
execution path (`M-FUNCTIONAL-03`, `M-TIME-03`, `M-ASYNC-04/05`, `S-IO-03/04`,
|
||||
`S-RUNTIME-02/03`) that gates `P-NETWORKED-02`/`P-RELOADABLE-02`. Then: foundation P2
|
||||
leftovers (D-036), then P3 platforms + `S-RPC-04/05`, then P4.
|
||||
Waves 1–11 (`P0`, `P1` incl. `M-FUNCTIONAL-03`/`M-TIME-03`, P2 execution/operations/storage/lifecycle/network modules, `VL-001`..`VL-013`, and P3 core subsystems `Discovery`, `Scheduler`, `Messaging`) are complete, verified, merged into `main`, and pushed. Next: **Wave 12** VoidForge upstream requests (`D-041`: `VL-STREAM-01`, `VL-PROC-01`, `VL-CRYPTO-01/02`, `VL-TEXT-01`, `VL-NET-W01`, `VL-NET-02`, `VL-WASM-01`, `VL-TOML-01`, `VL-MCP-01`, `VL-SQLITE-01..06`, `VL-SEC-01`) + root QA backlog (`X-QA-01..04`); then remaining P2 foundation tasks (`D-036`), P3 (`S-RPC-04/05`, `NetworkedApplications`, `ReloadableApplications`), and P4.
|
||||
@@ -146,19 +146,20 @@ verified by the available spawn response.
|
||||
|
||||
Baseline: `main` at `38436b1`; full RelWithDebInfo `-Werror` (`/tmp/void-w11-base`, 55 modules):
|
||||
`VoidTests` 1,484 discovered (1,480 ✔, 4 ⊘, 0 ✘) in 26.99 s; `ctest` 2/2 (111.68 s).
|
||||
Decisions: D-033..D-036.
|
||||
Post-fix integrated verification (`c6de784`): adversarial review (`CHANGES_REQUIRED`: 1 P1 + 7 P2 + 1 P3 on `7bea7df`) fixed in `c6de784` (+10 regression tests, post-fix review `READY`); full 55-module RelWithDebInfo `1,694` (`1,690 ✔`, `4 ⊘`, `0 ✘`), `ctest` `2/2` (`110.10s`, `41` consumers), Debug ASan+UBSan `1,694` (`0` leaks/UB), Debug TSan `1,035` (`1,032 ✔`, `3 ⊘`) + 3×`169/169 ✔` stress loop (`0` races).
|
||||
Decisions: D-033..D-043.
|
||||
|
||||
| ID | Deliverable | Spec | State | Verification summary |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| W11-PLAN | Architecture/task plan + REV1 addendum | [W11-PLAN](tasks/W11-PLAN.md), [output](tasks/W11-PLAN-OUTPUT.md), [REV1](tasks/W11-PLAN-REV1-OUTPUT.md) | DONE | PREFLIGHT 1 CHANGES_REQUIRED ([findings](tasks/W11-PREFLIGHT-OUTPUT.md)); resolved in REV1/D-038; PREFLIGHT 2 running |
|
||||
| M-FUNCTIONAL-03 | Pure retry decisions + named blocking adapter (A1) | [spec](tasks/M-FUNCTIONAL-03.md) | VERIFIED (`26edf65`) | Review W11-REVIEW-A1 READY (P3 1/2/5 fixed by root); ResilienceAsync subset 475 (472 ✔, 3 ⊘), filtered 43/43, ctest 2/2, TSan 40/40 0 races, ASan+UBSan 40/40, `-Werror` syntax checks clean |
|
||||
| M-TIME-03 | Injected-deadline domains: TimerQueue + clock saturation (B1); `retry_async` (B1b) | [spec](tasks/M-TIME-03.md), [B1b](tasks/M-TIME-03-B1b.md) | VERIFIED | B1b: review W11-REVIEW-B1b READY (deviation accepted, spec amended, doc P3-3 fixed); root 697 (694 ✔, 3 ⊘), TSan 33/33, reviewer ASan 33/33 + TSan 5×15/15 | B1: review W11-REVIEW-B1 F1–F3 fixed by root; Runtime;SystemAsync;ResilienceAsync 681 (678 ✔, 3 ⊘), TSan 28/28 ×3, ASan 468 ✔, post-fix 18/18 + TSan 15/15 |
|
||||
| M-ASYNC-04 | ThreadExecutor, FuturePool, AsyncChannel, bounded ParallelFor (A2) + root fixes: pre-existing `spawn()` eager-frame race in `Executor.hpp`, ParallelFor runner last-reference ownership | [spec](tasks/M-ASYNC-04.md) | IN REVIEW | Implementer: 109/109, TSan 46/46, ASan 46/46; root: TSan 6/6 runs 47/47 after fixes, spawn regression test added |
|
||||
| M-ASYNC-05 | EventBus/Observable snapshot dispatch, joined subscriptions (A3) | [spec](tasks/M-ASYNC-05.md) | READY (after M-ASYNC-04 commit) | — |
|
||||
| S-IO-03 | Bounded positional file workers, sync, active-cancel, shutdown core, D1 fixes (B2) | [spec](tasks/S-IO-03.md) | IN REVIEW | Implementer: IO 37/37, TSan 37/37 + 30 loops, ASan clean, downstream 883 ✔; root: full 55-module `-Werror` 1,574 (1,570 ✔, 4 ⊘), ctest 2/2, IO-users TSan 627 (624 ✔, 3 ⊘), 0 TSan warnings |
|
||||
| S-IO-04 | `Driver::run`, `pump_until`, SystemAsync shutdown conformance (A4) | [spec](tasks/S-IO-04.md) | READY (after S-IO-03 commit) | — |
|
||||
| S-RUNTIME-02 | Explicit start, readiness, reverse failed-start cleanup (combined with S-RUNTIME-03) | [spec](tasks/S-RUNTIME-02-03.md) | READY (after M-ASYNC-04, S-IO-04 commits) | — |
|
||||
| S-RUNTIME-03 | Structured shutdown, repeated join, exporter-before-executor ordering | [spec](tasks/S-RUNTIME-02-03.md) | READY (combined) | — |
|
||||
| W11-PLAN | Architecture/task plan + REV1 addendum + R2 contract | [W11-PLAN](tasks/W11-PLAN.md), [output](tasks/W11-PLAN-OUTPUT.md), [REV1](tasks/W11-PLAN-REV1-OUTPUT.md), [R2](tasks/W11-CONTRACT-R2.md) | DONE | PREFLIGHT 1 & 2 resolved via REV1/D-038 & R2/D-040; spec review S1–S9, A1–A3 adopted via D-042 |
|
||||
| M-FUNCTIONAL-03 | Pure retry decisions + named blocking adapter (A1) | [spec](tasks/M-FUNCTIONAL-03.md) | VERIFIED (`26edf65`) | Review W11-REVIEW-A1 READY; ResilienceAsync subset 475 (472 ✔, 3 ⊘), filtered 43/43, ctest 2/2, TSan 40/40 (0 races), ASan+UBSan 40/40; verified in post-W11 full suite (`c6de784`) |
|
||||
| M-TIME-03 | Injected-deadline domains: TimerQueue + clock saturation (B1); `retry_async` (B1b) | [spec](tasks/M-TIME-03.md), [B1b](tasks/M-TIME-03-B1b.md) | VERIFIED (`99a1100`, `5c24f8e`) | W11-REVIEW-B1 & B1b READY; root 697 (694 ✔, 3 ⊘), TSan 33/33 + 5×15/15, ASan 468 ✔; verified in post-W11 full/TSan suites (`c6de784`) |
|
||||
| M-ASYNC-04 | ThreadExecutor, FuturePool, AsyncChannel, bounded ParallelFor (A2) + `spawn()` race & ParallelFor last-ref fixes | [spec](tasks/M-ASYNC-04.md) | VERIFIED (`b2c8411`) | 109/109, TSan 6×47/47, ASan 46/46; verified in post-W11 full/ASan/TSan+3×stress suites (`c6de784`) |
|
||||
| M-ASYNC-05 | EventBus/Observable snapshot dispatch, joined subscriptions (A3) + post-review capture-lifetime & pumping self-join fixes | [spec](tasks/M-ASYNC-05.md) | VERIFIED (`ef85ce0`, `c6de784`) | Targeted TSan 110/110 ✔; verified in post-W11 full/ASan (`1,690 ✔`) & TSan (`1,032 ✔` + 3×`169/169 ✔`) |
|
||||
| S-IO-03 | Bounded positional file workers, sync, active-cancel, shutdown core, D1 fixes (B2) + `MockBackend::try_acquire` TOCTOU & epoll `EPOLLIN` fixes | [spec](tasks/S-IO-03.md) | VERIFIED (`1e752da`, `c6de784`) | IO 37/37, TSan 37/37 + 30 loops, ASan clean; post-fix `c6de784` full/ASan/TSan+3×stress (`1,690 ✔` / `1,032 ✔` + 3×`169/169 ✔`) |
|
||||
| S-IO-04 | `Driver::run`, `Pump.hpp` `pump_until`, SystemAsync shutdown conformance (A4) + steady_clock idle pacing fixes | [spec](tasks/S-IO-04.md) | VERIFIED (`50029e1`, `c6de784`) | Targeted & integrated post-W11 RelWithDebInfo, `ctest` 2/2 (`41` consumers), ASan+UBSan, & TSan+3×stress (`0` races) |
|
||||
| S-RUNTIME-02 | Explicit start, readiness, reverse failed-start cleanup + concurrent start/shutdown synchronization | [spec](tasks/S-RUNTIME-02-03.md) | VERIFIED (`7bea7df`, `c6de784`) | `verify_runtime.sh` 6/6 gates (incl. `nosys` & zero `Void/System/` includes), full/ASan/TSan+3×stress (`c6de784`) |
|
||||
| S-RUNTIME-03 | Structured shutdown, repeated join, exporter-before-executor ordering + embedded background-worker & poll exporter fixes | [spec](tasks/S-RUNTIME-02-03.md) | VERIFIED (`7bea7df`, `c6de784`) | `RuntimeStart`/`RuntimeSignals`/`RuntimeShutdown`/`RuntimeHost` `37/37 ✔` (RelWithDebInfo, TSan, ASan) & post-W11 full/ASan/TSan (`c6de784`) |
|
||||
|
||||
P0 characterization tasks (`M-*-01`, `S-ALGORITHMS-01`, `S-MEMORY-01`): folded into follow-on
|
||||
specs' observed baselines (D-035); not separately scheduled.
|
||||
|
||||
@@ -304,3 +304,8 @@ Branch: `feat/roadmap-p2-wave6b` (branched from `main` at `acd77ee`). Toolchain
|
||||
| Wave 10 full Debug ASan+UBSan (`60ee28e`) | `dev cpp-gcc -p libarchive -p openssl -p sqlite -p libsodium` Debug ASan+UBSan (`-Werror`, `/tmp/void-w10-asan`), 55 modules | **PASSED**: `1,484` discovered (`1,480 ✔`, `4 ⊘`, `0 ✘`) in `42.48s`, `0` leaks, `0` UB |
|
||||
| Wave 10 Debug TSan (`60ee28e`) | `dev cpp-gcc -p openssl` Debug TSan (`-Werror`, `/tmp/void-w10-tsan`), 23 modules (`Discovery;DiscoveryRpc;Scheduler;SchedulerStorage;Messaging;MessagingStorage;MessagingRpc;System;Testing`) | **PASSED**: `903` discovered (`900 ✔`, `3 ⊘`, `0 ✘`) in `23.20s`, `0` data races, `0` lock-order warnings |
|
||||
| Post-W10 Benchmark (`60ee28e`, `rev=60ee28e4ca9b`) | `/tmp/void-w10-full/benchmarks/VoidFoundationBench --json /tmp/void-w10-full/post-w10.json` (RelWithDebInfo, warmup=5, reps=20, ops=10000) | Medians: `harness_empty_loop` 0.39ns, `core_uuid_parse_hyphenated` 25.18ns, `core_uuid_to_string` 16.66ns, `core_hash_fnv1a64_256b` 182.46ns, `core_hash_murmur3_256b` 68.53ns, `functional_result_ok_chain` 1.14ns, `functional_error_with_context` 59.10ns, `math_checked_add_loop` 0.47ns, `containers_spsc_ring_push_pop` 8.85ns, `containers_lru_get_put` 20.87ns, `binary_reader_u64_be` 1.14ns, `data_json_parse_small_object` 287.18ns, `data_json_serialize_small_object` 164.76ns |
|
||||
| Wave 11 adversarial review & targeted fixes (`c6de784`) | Fresh adversarial review (`925b2cd8-7c57-4121-b6c5-b925c6a434f6`) on `7bea7df` -> `c6de784` (`verify_w11_fixes.sh` + `verify_runtime.sh`: Debug TSan `Async;IO;Runtime;System;Testing` + 6 Runtime gates, `-Werror`) | Review `CHANGES_REQUIRED` (1 P1 + 7 P2 + 1 P3) resolved in `c6de784` (+10 regression tests); post-fix review `READY`. Targeted TSan `110/110 ✔` in `599.1ms`; `verify_runtime.sh` 6/6 gates passed (`37/37 ✔` RelWithDebInfo, `nosys` `ctest` 2/2, TSan, ASan `224.8ms`, zero `Void/System/` includes in `include/Void/Runtime/**`) |
|
||||
| Wave 11 integrated RelWithDebInfo + consumers (`c6de784`) | `dev cpp-gcc -p libarchive -p openssl -p sqlite -p libsodium` RelWithDebInfo (`-Werror`, `/tmp/void-w11-full`), 55 modules, `VoidTests` + `ctest` | **PASSED**: `1,694` discovered (`1,690 ✔`, `4 ⊘` skipped, `0 ✘`) in `25.13s`; `ctest` `2/2` in `110.10s` (`VoidTests` `25.01s`, `VoidInstalledComponentConsumers` `85.09s` across all `41` consumers) |
|
||||
| Wave 11 full Debug ASan+UBSan (`c6de784`) | `dev cpp-gcc -p libarchive -p openssl -p sqlite -p libsodium` Debug ASan+UBSan (`-Werror`, `/tmp/void-w11-asan`, `ASAN_OPTIONS=detect_leaks=1:halt_on_error=1`, `UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1`), 55 modules | **PASSED**: `1,694` discovered (`1,690 ✔`, `4 ⊘` skipped, `0 ✘`) in `67.61s`, `0` leaks, `0` UB |
|
||||
| Wave 11 Debug TSan + 3x stress loop (`c6de784`) | `dev cpp-gcc` Debug TSan (`-Werror`, `/tmp/void-w11-tsan`, `TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1`), 21 modules (`Async;IO;IPC;SystemAsync;Storage;Runtime;ConfigurationAsync;System;Testing`) | **PASSED**: unfiltered `1,035` (`1,032 ✔`, `3 ⊘` skipped, `0 ✘`) in `34.78s`; 3x Wave 11 stress loop `169/169 ✔` (`2.12s`, `3.07s`, `2.14s`), `0` data races / lock-order warnings |
|
||||
| Post-W11 Benchmark (`c6de784`, `rev=c6de7842f732`) | `/tmp/void-w11-full/benchmarks/VoidFoundationBench --json /tmp/void-w11-full/post-w11.json` (RelWithDebInfo, warmup=5, reps=20, ops=10000) | Medians: `harness_empty_loop` 0.40ns, `core_uuid_parse_hyphenated` 26.06ns, `core_uuid_to_string` 18.06ns, `core_hash_fnv1a64_256b` 186.38ns, `core_hash_murmur3_256b` 69.57ns, `functional_result_ok_chain` 1.16ns, `functional_error_with_context` 61.13ns, `math_checked_add_loop` 0.50ns, `containers_spsc_ring_push_pop` 9.33ns, `containers_lru_get_put` 22.02ns, `binary_reader_u64_be` 1.19ns, `data_json_parse_small_object` 302.08ns, `data_json_serialize_small_object` 170.90ns |
|
||||
@@ -240,6 +240,27 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
|
||||
}
|
||||
}
|
||||
|
||||
void finish_entry_dispatch(const std::shared_ptr<SubEntry>& entry) noexcept
|
||||
{
|
||||
for (;;) {
|
||||
std::function<void(const void*)> cleanup_fn;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
if (!entry->active && entry->in_flight == 1 && entry->handler) {
|
||||
cleanup_fn = std::move(entry->handler);
|
||||
} else {
|
||||
--entry->in_flight;
|
||||
--total_in_flight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Destroy captured state outside mu while in_flight >= 1 so
|
||||
// join_entry / close_and_join / ~EventBus cannot return early.
|
||||
cleanup_fn = {};
|
||||
}
|
||||
done_cv.notify_all();
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void> join_entry(
|
||||
const std::shared_ptr<SubEntry>& entry)
|
||||
{
|
||||
@@ -298,10 +319,11 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
|
||||
const void* ev_raw = item.event.get();
|
||||
for (auto& rec : item.recipients) {
|
||||
std::function<void(const void*)> fn;
|
||||
std::function<void(const void*)> discarded_legacy;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
if (closed || rec.entry->purged) {
|
||||
rec.legacy_fn = {};
|
||||
discarded_legacy = std::move(rec.legacy_fn);
|
||||
continue;
|
||||
}
|
||||
if (!rec.legacy_fn && !rec.entry->active) {
|
||||
@@ -326,18 +348,7 @@ struct BusCore : std::enable_shared_from_this<BusCore> {
|
||||
}
|
||||
fn = {};
|
||||
|
||||
std::function<void(const void*)> cleanup_fn;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
--rec.entry->in_flight;
|
||||
--total_in_flight;
|
||||
if (!rec.entry->active && rec.entry->in_flight == 0 &&
|
||||
rec.entry->handler) {
|
||||
cleanup_fn = std::move(rec.entry->handler);
|
||||
}
|
||||
}
|
||||
done_cv.notify_all();
|
||||
cleanup_fn = {};
|
||||
finish_entry_dispatch(rec.entry);
|
||||
}
|
||||
|
||||
// Destroy event payload and recipient handles before completion notify.
|
||||
@@ -460,17 +471,7 @@ inline DispatchCoroutine make_injected_dispatch(
|
||||
}
|
||||
fn = {};
|
||||
|
||||
std::function<void(const void*)> cleanup_fn;
|
||||
{
|
||||
std::lock_guard lk{core->mu};
|
||||
--entry->in_flight;
|
||||
--core->total_in_flight;
|
||||
if (!entry->active && entry->in_flight == 0 && entry->handler) {
|
||||
cleanup_fn = std::move(entry->handler);
|
||||
}
|
||||
}
|
||||
core->done_cv.notify_all();
|
||||
cleanup_fn = {};
|
||||
core->finish_entry_dispatch(entry);
|
||||
}
|
||||
|
||||
snapshot.clear();
|
||||
@@ -709,18 +710,7 @@ public:
|
||||
~EntryExitGuard()
|
||||
{
|
||||
fn_ref = {};
|
||||
std::function<void(const void*)> cleanup;
|
||||
{
|
||||
std::lock_guard lk{core->mu};
|
||||
--entry->in_flight;
|
||||
--core->total_in_flight;
|
||||
if (!entry->active && entry->in_flight == 0 &&
|
||||
entry->handler) {
|
||||
cleanup = std::move(entry->handler);
|
||||
}
|
||||
}
|
||||
core->done_cv.notify_all();
|
||||
cleanup = {};
|
||||
core->finish_entry_dispatch(entry);
|
||||
}
|
||||
} exit_guard{core, entry, fn};
|
||||
|
||||
@@ -933,6 +923,11 @@ public:
|
||||
Void::Async::AsyncErrorCode::invalid_argument,
|
||||
"EventBus::flush_pumping requires a matching ManualExecutor")};
|
||||
}
|
||||
if (detail::is_on_bus_callback(core_.get())) {
|
||||
return std::unexpected{Void::Async::make_async_error(
|
||||
Void::Async::AsyncErrorCode::self_join,
|
||||
"EventBus::flush_pumping cannot be called from inside a callback")};
|
||||
}
|
||||
std::uint64_t target = 0;
|
||||
{
|
||||
std::lock_guard lk{core_->mu};
|
||||
@@ -1036,6 +1031,11 @@ public:
|
||||
Void::Async::AsyncErrorCode::invalid_argument,
|
||||
"EventBus::close_and_join_pumping requires a matching ManualExecutor")};
|
||||
}
|
||||
if (detail::is_on_bus_callback(core_.get())) {
|
||||
return std::unexpected{Void::Async::make_async_error(
|
||||
Void::Async::AsyncErrorCode::self_join,
|
||||
"EventBus::close_and_join_pumping cannot be called from inside a callback")};
|
||||
}
|
||||
|
||||
std::vector<std::function<void(const void*)>> to_drop;
|
||||
{
|
||||
|
||||
@@ -187,12 +187,16 @@ public:
|
||||
};
|
||||
|
||||
std::size_t total = 0;
|
||||
std::size_t consecutive_fast_zero = 0;
|
||||
while (!stop.stop_requested() && !shutdown_complete()) {
|
||||
const auto poll_start = std::chrono::steady_clock::now();
|
||||
auto res = poll_once(max_wait);
|
||||
const auto poll_elapsed = std::chrono::steady_clock::now() - poll_start;
|
||||
if (!res.has_value()) {
|
||||
if (res.error().code().domain == Void::Result::kIoErrorDomain &&
|
||||
res.error().code().value ==
|
||||
static_cast<std::int32_t>(IoErrorCode::busy)) {
|
||||
consecutive_fast_zero = 0;
|
||||
const auto busy_slice =
|
||||
max_wait > std::chrono::nanoseconds{0}
|
||||
? std::min(max_wait,
|
||||
@@ -206,9 +210,19 @@ public:
|
||||
return std::unexpected{std::move(res.error())};
|
||||
}
|
||||
total += *res;
|
||||
if (*res == 0 && active_backend() == BackendPreference::mock &&
|
||||
max_wait > std::chrono::nanoseconds{0}) {
|
||||
wait_stop_aware(max_wait);
|
||||
if (*res == 0 && max_wait > std::chrono::nanoseconds{0} &&
|
||||
poll_elapsed < max_wait) {
|
||||
const auto remain = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
max_wait - poll_elapsed);
|
||||
if (active_backend() == BackendPreference::mock) {
|
||||
wait_stop_aware(remain);
|
||||
} else if (++consecutive_fast_zero >= 2) {
|
||||
wait_stop_aware(std::min(
|
||||
remain,
|
||||
std::chrono::nanoseconds{std::chrono::milliseconds{1}}));
|
||||
}
|
||||
} else {
|
||||
consecutive_fast_zero = 0;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
|
||||
@@ -102,7 +102,9 @@ template <class Done>
|
||||
wait = std::chrono::nanoseconds{0};
|
||||
}
|
||||
|
||||
const auto poll_start = std::chrono::steady_clock::now();
|
||||
auto poll_res = driver.poll_once(wait);
|
||||
const auto poll_elapsed = std::chrono::steady_clock::now() - poll_start;
|
||||
if (!poll_res.has_value()) {
|
||||
if (poll_res.error().code().domain == Void::Result::kIoErrorDomain &&
|
||||
poll_res.error().code().value ==
|
||||
@@ -119,12 +121,13 @@ template <class Done>
|
||||
}
|
||||
return std::unexpected{std::move(poll_res.error())};
|
||||
}
|
||||
total_work += *poll_res;
|
||||
std::size_t turn_work = *poll_res;
|
||||
|
||||
if (options.timers != nullptr) {
|
||||
total_work += options.timers->poll_expired();
|
||||
turn_work += options.timers->poll_expired();
|
||||
}
|
||||
total_work += manual.drain();
|
||||
turn_work += manual.drain();
|
||||
total_work += turn_work;
|
||||
|
||||
if (done()) {
|
||||
return total_work;
|
||||
@@ -132,6 +135,15 @@ template <class Done>
|
||||
if (driver.shutdown_complete()) {
|
||||
return total_work;
|
||||
}
|
||||
if (turn_work == 0 && manual.empty() &&
|
||||
wait > std::chrono::nanoseconds{0} && poll_elapsed < wait) {
|
||||
const auto remain = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
wait - poll_elapsed);
|
||||
const auto slice = std::min(
|
||||
remain,
|
||||
std::chrono::nanoseconds{std::chrono::milliseconds{1}});
|
||||
wait_stop_aware(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,7 @@ struct HostCore {
|
||||
std::vector<std::string> started_component_ids{};
|
||||
|
||||
ShutdownPhase phase{ShutdownPhase::not_started};
|
||||
bool start_running{false};
|
||||
bool shutdown_running{false};
|
||||
bool begin_shutdown_called{false};
|
||||
bool failed_start_incomplete{false};
|
||||
@@ -255,6 +256,23 @@ struct HostCore {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (embedded.executor != nullptr &&
|
||||
embedded.executor->has_background_workers()) {
|
||||
for (;;) {
|
||||
auto r = shutdown_blocking_impl(
|
||||
Async::OperationOptions{.deadline = TimePoint::max()},
|
||||
/*unbounded=*/true);
|
||||
if (!r.has_value()) {
|
||||
std::fputs(
|
||||
"Void::Runtime::Host (embedded background-worker executor) "
|
||||
"destructor could not complete shutdown; terminating\n",
|
||||
stderr);
|
||||
std::terminate();
|
||||
}
|
||||
if (r->complete) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::fputs(
|
||||
"Void::Runtime::Host (embedded non-ManualExecutor) destroyed before "
|
||||
@@ -370,12 +388,24 @@ struct HostCore {
|
||||
if (tl_reactor_host() == this) {
|
||||
return true;
|
||||
}
|
||||
if (!options.embedded_mode && owned_executor &&
|
||||
owned_executor->is_executor_thread()) {
|
||||
if (options.embedded_mode) {
|
||||
if (embedded.executor != nullptr &&
|
||||
embedded.executor->is_executor_thread()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Async::ThreadExecutor* exec = nullptr;
|
||||
bool has_drv = false;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
exec = owned_executor.get();
|
||||
has_drv = (owned_driver != nullptr);
|
||||
}
|
||||
if (exec != nullptr && exec->is_executor_thread()) {
|
||||
return true;
|
||||
}
|
||||
if (!options.embedded_mode && owned_driver &&
|
||||
IO::is_io_worker_thread()) {
|
||||
if (has_drv && IO::is_io_worker_thread()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -513,7 +543,11 @@ struct HostCore {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
IO::Driver* drv = get_io();
|
||||
IO::Driver* drv = nullptr;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
drv = get_io();
|
||||
}
|
||||
if (drv == nullptr) {
|
||||
return pred();
|
||||
}
|
||||
@@ -524,8 +558,25 @@ struct HostCore {
|
||||
opts.operation.deadline = deadline;
|
||||
}
|
||||
opts.timers = timers;
|
||||
(void)IO::pump_until(*drv, manual, pred, opts);
|
||||
return pred();
|
||||
for (;;) {
|
||||
auto r = IO::pump_until(*drv, manual, pred, opts);
|
||||
if (pred()) {
|
||||
return true;
|
||||
}
|
||||
if (single_drain_if_poll || stop.stop_requested()) {
|
||||
return false;
|
||||
}
|
||||
if (deadline != TimePoint::max() && active_clock().now() >= deadline) {
|
||||
return pred();
|
||||
}
|
||||
if (!r.has_value() &&
|
||||
r.error().code().domain == Void::Result::kIoErrorDomain &&
|
||||
r.error().code().value ==
|
||||
static_cast<std::int32_t>(IO::IoErrorCode::exhausted)) {
|
||||
continue;
|
||||
}
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
|
||||
void run_reactor_loop()
|
||||
@@ -560,12 +611,16 @@ struct HostCore {
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t consecutive_fast_zero = 0;
|
||||
while (!stop.stop_requested() && !owned_driver->shutdown_complete()) {
|
||||
const auto poll_start = std::chrono::steady_clock::now();
|
||||
auto r = owned_driver->poll_once(kMaxWait);
|
||||
const auto poll_elapsed = std::chrono::steady_clock::now() - poll_start;
|
||||
if (!r.has_value()) {
|
||||
if (r.error().code().domain == Void::Result::kIoErrorDomain &&
|
||||
r.error().code().value ==
|
||||
static_cast<std::int32_t>(IO::IoErrorCode::busy)) {
|
||||
consecutive_fast_zero = 0;
|
||||
wait_stop_aware(std::chrono::milliseconds{1});
|
||||
continue;
|
||||
}
|
||||
@@ -573,9 +628,18 @@ struct HostCore {
|
||||
}
|
||||
reactor_turns.fetch_add(1, std::memory_order_release);
|
||||
cv.notify_all();
|
||||
if (*r == 0 &&
|
||||
owned_driver->active_backend() == IO::BackendPreference::mock) {
|
||||
wait_stop_aware(kMaxWait);
|
||||
if (*r == 0 && poll_elapsed < kMaxWait) {
|
||||
const auto remain = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
kMaxWait - poll_elapsed);
|
||||
if (owned_driver->active_backend() == IO::BackendPreference::mock) {
|
||||
wait_stop_aware(remain);
|
||||
} else if (++consecutive_fast_zero >= 2) {
|
||||
wait_stop_aware(std::min(
|
||||
remain,
|
||||
std::chrono::nanoseconds{std::chrono::milliseconds{1}}));
|
||||
}
|
||||
} else {
|
||||
consecutive_fast_zero = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,9 +740,12 @@ struct HostCore {
|
||||
auto io_rep = owned_driver->shutdown(
|
||||
Async::OperationOptions{.deadline = cleanup_dl});
|
||||
if (!io_rep.has_value() || !io_rep->complete) {
|
||||
const std::size_t file_workers_alive =
|
||||
owned_driver->telemetry().file_workers_running;
|
||||
std::lock_guard lk{mu};
|
||||
started_workers =
|
||||
owned_executor ? options.cpu_workers : 0;
|
||||
(owned_executor ? options.cpu_workers : 0) +
|
||||
file_workers_alive;
|
||||
failed_start_incomplete = true;
|
||||
last_report = build_report_locked(false);
|
||||
return;
|
||||
@@ -752,12 +819,23 @@ struct HostCore {
|
||||
"Host::start requires HostState::constructed")};
|
||||
}
|
||||
state = HostState::starting;
|
||||
start_running = true;
|
||||
owner_thread = std::this_thread::get_id();
|
||||
start_options = std::move(opts);
|
||||
signal_gate = start_options.signal_gate;
|
||||
on_phase = start_options.on_phase;
|
||||
}
|
||||
|
||||
struct StartGuard {
|
||||
HostCore& self;
|
||||
~StartGuard()
|
||||
{
|
||||
std::lock_guard lk{self.mu};
|
||||
self.start_running = false;
|
||||
self.cv.notify_all();
|
||||
}
|
||||
} start_guard{*this};
|
||||
|
||||
const auto fail_at = [&](StartStep step, Void::Result::Error err)
|
||||
-> Void::Result::Result<void> {
|
||||
{
|
||||
@@ -815,17 +893,28 @@ struct HostCore {
|
||||
if (!exec_res.has_value()) {
|
||||
return fail_at(StartStep::cpu_executor, std::move(exec_res.error()));
|
||||
}
|
||||
owned_executor = std::move(*exec_res);
|
||||
if (auto st = owned_executor->start(); !st.has_value()) {
|
||||
Async::ThreadExecutor* exec_raw = exec_res->get();
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
owned_executor = std::move(*exec_res);
|
||||
}
|
||||
if (auto st = exec_raw->start(); !st.has_value()) {
|
||||
return fail_at(StartStep::cpu_executor, std::move(st.error()));
|
||||
}
|
||||
business_scope = std::make_unique<Async::TaskScope>(
|
||||
*owned_executor,
|
||||
auto scope_local = std::make_unique<Async::TaskScope>(
|
||||
*exec_raw,
|
||||
Async::TaskScopeOptions{
|
||||
.max_tasks = options.limits.max_cpu_tasks,
|
||||
.stop_on_first_error = false,
|
||||
},
|
||||
active_clock());
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
business_scope = std::move(scope_local);
|
||||
if (admission_closed) {
|
||||
business_scope->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: io_driver
|
||||
if (auto sr = run_before_step(StartStep::io_driver); !sr.has_value()) {
|
||||
@@ -840,17 +929,21 @@ struct HostCore {
|
||||
};
|
||||
}
|
||||
auto drv_res = IO::Driver::create(
|
||||
*owned_executor, std::move(io_opts), active_clock(), &active_budget());
|
||||
*exec_raw, std::move(io_opts), active_clock(), &active_budget());
|
||||
if (!drv_res.has_value()) {
|
||||
return fail_at(StartStep::io_driver, std::move(drv_res.error()));
|
||||
}
|
||||
owned_driver = std::move(*drv_res);
|
||||
IO::Driver* drv_raw = drv_res->get();
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
owned_driver = std::move(*drv_res);
|
||||
}
|
||||
|
||||
// Step 5: file_workers
|
||||
if (auto sr = run_before_step(StartStep::file_workers); !sr.has_value()) {
|
||||
return fail_at(StartStep::file_workers, std::move(sr.error()));
|
||||
}
|
||||
if (auto fw = owned_driver->start_file_workers(); !fw.has_value()) {
|
||||
if (auto fw = drv_raw->start_file_workers(); !fw.has_value()) {
|
||||
return fail_at(StartStep::file_workers, std::move(fw.error()));
|
||||
}
|
||||
|
||||
@@ -877,13 +970,18 @@ struct HostCore {
|
||||
started_workers = options.cpu_workers + options.file_workers + 1;
|
||||
}
|
||||
} else {
|
||||
business_scope = std::make_unique<Async::TaskScope>(
|
||||
auto scope_local = std::make_unique<Async::TaskScope>(
|
||||
*embedded.executor,
|
||||
Async::TaskScopeOptions{
|
||||
.max_tasks = options.limits.max_cpu_tasks,
|
||||
.stop_on_first_error = false,
|
||||
},
|
||||
active_clock());
|
||||
std::lock_guard lk{mu};
|
||||
business_scope = std::move(scope_local);
|
||||
if (admission_closed) {
|
||||
business_scope->close();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 7: components in startup_order (outside mu)
|
||||
@@ -898,17 +996,27 @@ struct HostCore {
|
||||
active_budget(),
|
||||
business_stop_source.get_token()};
|
||||
for (const auto& id : plan.startup_order) {
|
||||
auto it = registered_components.find(id);
|
||||
if (it == registered_components.end() || !it->second) {
|
||||
std::shared_ptr<ComponentEntry> entry;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
auto it = registered_components.find(id);
|
||||
if (it != registered_components.end()) {
|
||||
entry = it->second;
|
||||
}
|
||||
}
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
auto comp_res = it->second->component->start(ctx);
|
||||
auto comp_res = entry->component->start(ctx);
|
||||
if (!comp_res.has_value()) {
|
||||
return fail_at(
|
||||
StartStep::components, std::move(comp_res.error()));
|
||||
}
|
||||
it->second->started = true;
|
||||
started_component_ids.push_back(id);
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
entry->started = true;
|
||||
started_component_ids.push_back(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -954,8 +1062,16 @@ struct HostCore {
|
||||
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
state = HostState::running;
|
||||
ready = true;
|
||||
if (admission_closed || begin_shutdown_called) {
|
||||
state = HostState::stopping_admission;
|
||||
ready = false;
|
||||
if (business_scope) {
|
||||
business_scope->close();
|
||||
}
|
||||
} else {
|
||||
state = HostState::running;
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@@ -994,9 +1110,15 @@ struct HostCore {
|
||||
"Host::shutdown_blocking called from an owned worker, reactor, or IO "
|
||||
"worker thread")};
|
||||
}
|
||||
if (options.embedded_mode ||
|
||||
(active_executor() != nullptr &&
|
||||
!active_executor()->has_background_workers())) {
|
||||
bool lacks_bg_workers = false;
|
||||
{
|
||||
std::lock_guard lk{mu};
|
||||
if (auto* exec = active_executor();
|
||||
exec != nullptr && !exec->has_background_workers()) {
|
||||
lacks_bg_workers = true;
|
||||
}
|
||||
}
|
||||
if (lacks_bg_workers) {
|
||||
return std::unexpected{make_runtime_error(
|
||||
RuntimeErrorCode::invalid_argument,
|
||||
"Host::shutdown_blocking requires background workers; use shutdown_pumping")};
|
||||
@@ -1071,7 +1193,13 @@ private:
|
||||
|
||||
{
|
||||
std::unique_lock lk{mu};
|
||||
while (shutdown_running) {
|
||||
if (start_running && owner_thread.has_value() &&
|
||||
std::this_thread::get_id() == *owner_thread) {
|
||||
return std::unexpected{make_runtime_error(
|
||||
RuntimeErrorCode::invalid_state,
|
||||
"Host shutdown cannot be called reentrantly from Host::start")};
|
||||
}
|
||||
while (start_running || shutdown_running) {
|
||||
if (!unbounded && opts.stop.stop_requested()) {
|
||||
return build_report_locked(false);
|
||||
}
|
||||
@@ -1339,6 +1467,7 @@ private:
|
||||
return true;
|
||||
};
|
||||
|
||||
bool polled_once = false;
|
||||
for (;;) {
|
||||
if (all_exporters_done()) {
|
||||
break;
|
||||
@@ -1355,6 +1484,14 @@ private:
|
||||
if (flushed_expired_now) {
|
||||
(void)exporter_stop_source.request_stop();
|
||||
}
|
||||
if (single_drain_if_poll && !polled_once &&
|
||||
manual != nullptr && !opts.stop.stop_requested()) {
|
||||
polled_once = true;
|
||||
(void)manual->drain();
|
||||
if (all_exporters_done()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (deadline_or_stop()) {
|
||||
return return_incomplete();
|
||||
}
|
||||
@@ -1450,8 +1587,12 @@ private:
|
||||
}
|
||||
auto io_rep = owned_driver->shutdown(std::move(io_op));
|
||||
if (!io_rep.has_value() || !io_rep->complete) {
|
||||
const std::size_t file_workers_alive =
|
||||
owned_driver->telemetry().file_workers_running;
|
||||
std::lock_guard lk{mu};
|
||||
started_workers = options.cpu_workers;
|
||||
started_workers =
|
||||
(owned_executor ? options.cpu_workers : 0) +
|
||||
file_workers_alive;
|
||||
state = HostState::shutdown_incomplete;
|
||||
last_report = build_report_locked(false);
|
||||
return *last_report;
|
||||
|
||||
+64
-61
@@ -189,6 +189,7 @@ struct DescriptorSlot {
|
||||
bool close_enqueued{false};
|
||||
bool eof_seen{false};
|
||||
bool epoll_registered{false};
|
||||
bool epoll_in_armed{false};
|
||||
bool epoll_out_armed{false};
|
||||
// S5: a File occupies a slot with fd == -1; socket paths skip it and the
|
||||
// file descriptor lives only in FileState.
|
||||
@@ -731,6 +732,8 @@ protected:
|
||||
virtual std::size_t drain_socket_queues(std::vector<Async::ResumeTicket>& tickets) = 0;
|
||||
// Stopping: the slot's interest is dropped (poll owner only, mu_ held).
|
||||
virtual void on_slot_abort_locked(DescriptorSlot&) noexcept {}
|
||||
// Called under mu_ right after an op is cleared from a slot.
|
||||
virtual void on_op_retired_locked(DescriptorSlot&) noexcept {}
|
||||
// Shutdown step 5 for socket slots (mu_ held): close the native fd.
|
||||
[[nodiscard]] virtual bool closes_native_fds() const noexcept { return false; }
|
||||
virtual void on_slot_final_close_locked(DescriptorSlot&) noexcept {}
|
||||
@@ -800,6 +803,7 @@ protected:
|
||||
s.close_enqueued = false;
|
||||
s.eof_seen = false;
|
||||
s.epoll_registered = false;
|
||||
s.epoll_in_armed = false;
|
||||
s.epoll_out_armed = false;
|
||||
s.is_file = false;
|
||||
s.file.reset();
|
||||
@@ -830,6 +834,7 @@ protected:
|
||||
s.close_enqueued = false;
|
||||
s.eof_seen = false;
|
||||
s.epoll_registered = false;
|
||||
s.epoll_in_armed = false;
|
||||
s.epoll_out_armed = false;
|
||||
s.is_file = false;
|
||||
s.file.reset();
|
||||
@@ -867,6 +872,7 @@ protected:
|
||||
} else if (op.dir == Direction::write && slot.active_write.get() == &op) {
|
||||
slot.active_write.reset();
|
||||
}
|
||||
on_op_retired_locked(slot);
|
||||
if (slot.closing && !slot.active_read && !slot.active_write &&
|
||||
kind() == BackendPreference::mock) {
|
||||
ready_close_waiters.insert(
|
||||
@@ -886,10 +892,14 @@ protected:
|
||||
bool complete_op_and_collect_tickets(const std::shared_ptr<PendingOp>& op,
|
||||
const Void::Result::Result<Transfer>& res,
|
||||
std::vector<Async::ResumeTicket>& out_tickets,
|
||||
std::vector<CloseWaiter>& close_waiters)
|
||||
std::vector<CloseWaiter>& close_waiters,
|
||||
bool skip_if_executing = false)
|
||||
{
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
if (skip_if_executing && op->in_execution) {
|
||||
return false;
|
||||
}
|
||||
if (op->retired) {
|
||||
duplicate_completions_ignored_.fetch_add(1, std::memory_order_acq_rel);
|
||||
return false;
|
||||
@@ -970,7 +980,8 @@ protected:
|
||||
op,
|
||||
std::unexpected{make_io_error(IoErrorCode::closed, "IO Driver shut down")},
|
||||
tickets,
|
||||
close_waiters)) {
|
||||
close_waiters,
|
||||
/*skip_if_executing=*/true)) {
|
||||
++done;
|
||||
}
|
||||
}
|
||||
@@ -1774,11 +1785,15 @@ public:
|
||||
[[nodiscard]] std::size_t pending_count(DescriptorId id, Direction dir) const noexcept
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
if (stopping_.load(std::memory_order_acquire) ||
|
||||
shutdown_begun_.load(std::memory_order_acquire)) {
|
||||
return 0;
|
||||
}
|
||||
if (!id.valid() || id.slot >= slots_.size()) {
|
||||
return 0;
|
||||
}
|
||||
const auto& s = slots_[id.slot];
|
||||
if (!s.in_use || s.is_file || s.id.generation != id.generation) {
|
||||
if (!s.in_use || s.is_file || s.closing || s.id.generation != id.generation) {
|
||||
return 0;
|
||||
}
|
||||
const auto& op = (dir == Direction::read) ? s.active_read : s.active_write;
|
||||
@@ -1789,11 +1804,15 @@ public:
|
||||
try_acquire(DescriptorId id, Direction dir)
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
if (stopping_.load(std::memory_order_acquire) ||
|
||||
shutdown_begun_.load(std::memory_order_acquire)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (!id.valid() || id.slot >= slots_.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto& s = slots_[id.slot];
|
||||
if (!s.in_use || s.is_file || s.id.generation != id.generation) {
|
||||
if (!s.in_use || s.is_file || s.closing || s.id.generation != id.generation) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto& op = (dir == Direction::read) ? s.active_read : s.active_write;
|
||||
@@ -1909,19 +1928,12 @@ protected:
|
||||
std::size_t processed = 0;
|
||||
std::vector<CloseWaiter> close_waiters;
|
||||
for (const auto& op : cancels) {
|
||||
bool executing = false;
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
executing = op->in_execution && !op->retired;
|
||||
}
|
||||
if (executing) {
|
||||
continue; // Held by a MockController token: stop intent only.
|
||||
}
|
||||
if (complete_op_and_collect_tickets(
|
||||
op,
|
||||
std::unexpected{make_io_error(IoErrorCode::cancelled, "IO operation cancelled")},
|
||||
tickets,
|
||||
close_waiters)) {
|
||||
close_waiters,
|
||||
/*skip_if_executing=*/true)) {
|
||||
++processed;
|
||||
}
|
||||
}
|
||||
@@ -2020,19 +2032,12 @@ private:
|
||||
std::size_t processed = 0;
|
||||
std::vector<CloseWaiter> close_waiters;
|
||||
for (const auto& op : expired) {
|
||||
bool executing = false;
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
executing = op->in_execution && !op->retired;
|
||||
}
|
||||
if (executing) {
|
||||
continue;
|
||||
}
|
||||
if (complete_op_and_collect_tickets(
|
||||
op,
|
||||
std::unexpected{make_io_error(IoErrorCode::timeout, "IO operation timed out")},
|
||||
tickets,
|
||||
close_waiters)) {
|
||||
close_waiters,
|
||||
/*skip_if_executing=*/true)) {
|
||||
++processed;
|
||||
}
|
||||
}
|
||||
@@ -2375,9 +2380,15 @@ protected:
|
||||
(void)::epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, s.fd, nullptr);
|
||||
}
|
||||
s.epoll_registered = false;
|
||||
s.epoll_in_armed = false;
|
||||
s.epoll_out_armed = false;
|
||||
}
|
||||
|
||||
void on_op_retired_locked(DescriptorSlot& s) noexcept override
|
||||
{
|
||||
sync_epoll_interest_locked(s);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool closes_native_fds() const noexcept override { return true; }
|
||||
|
||||
void on_slot_final_close_locked(DescriptorSlot& s) noexcept override
|
||||
@@ -2395,7 +2406,9 @@ protected:
|
||||
Direction dir,
|
||||
const std::shared_ptr<PendingOp>&) override
|
||||
{
|
||||
if (!slot.epoll_registered || (dir == Direction::write && !slot.epoll_out_armed)) {
|
||||
if (!slot.epoll_registered ||
|
||||
(dir == Direction::read && !slot.epoll_in_armed) ||
|
||||
(dir == Direction::write && !slot.epoll_out_armed)) {
|
||||
control_queue_.push_back(ControlAction{ControlAction::Type::arm_interest, slot.id});
|
||||
}
|
||||
return {};
|
||||
@@ -2427,13 +2440,30 @@ private:
|
||||
|
||||
void sync_epoll_interest_locked(DescriptorSlot& slot) noexcept
|
||||
{
|
||||
if (!slot.in_use || slot.is_file || slot.fd < 0 || slot.closing || epoll_fd_ < 0) {
|
||||
if (!slot.in_use || slot.is_file || slot.fd < 0 || epoll_fd_ < 0) {
|
||||
return;
|
||||
}
|
||||
const bool want_in =
|
||||
!slot.closing &&
|
||||
(slot.active_read != nullptr && !slot.active_read->retired);
|
||||
const bool want_out =
|
||||
!slot.closing &&
|
||||
(slot.active_write != nullptr && !slot.active_write->retired);
|
||||
if (!want_in && !want_out) {
|
||||
if (slot.epoll_registered) {
|
||||
(void)::epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, slot.fd, nullptr);
|
||||
slot.epoll_registered = false;
|
||||
slot.epoll_in_armed = false;
|
||||
slot.epoll_out_armed = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const bool want_out = (slot.active_write != nullptr && !slot.active_write->retired);
|
||||
epoll_event ev{};
|
||||
std::uint32_t events = static_cast<std::uint32_t>(EPOLLIN) |
|
||||
static_cast<std::uint32_t>(EPOLLRDHUP);
|
||||
std::uint32_t events = 0;
|
||||
if (want_in) {
|
||||
events |= static_cast<std::uint32_t>(EPOLLIN) |
|
||||
static_cast<std::uint32_t>(EPOLLRDHUP);
|
||||
}
|
||||
if (want_out) {
|
||||
events |= static_cast<std::uint32_t>(EPOLLOUT);
|
||||
}
|
||||
@@ -2442,10 +2472,12 @@ private:
|
||||
if (!slot.epoll_registered) {
|
||||
if (::epoll_ctl(epoll_fd_, EPOLL_CTL_ADD, slot.fd, &ev) == 0) {
|
||||
slot.epoll_registered = true;
|
||||
slot.epoll_in_armed = want_in;
|
||||
slot.epoll_out_armed = want_out;
|
||||
}
|
||||
} else if (slot.epoll_out_armed != want_out) {
|
||||
} else if (slot.epoll_in_armed != want_in || slot.epoll_out_armed != want_out) {
|
||||
if (::epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, slot.fd, &ev) == 0) {
|
||||
slot.epoll_in_armed = want_in;
|
||||
slot.epoll_out_armed = want_out;
|
||||
}
|
||||
}
|
||||
@@ -2485,30 +2517,12 @@ private:
|
||||
}
|
||||
|
||||
for (const auto& op : cancels) {
|
||||
bool executing = false;
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
executing = op->in_execution && !op->retired;
|
||||
if (!executing && !op->retired &&
|
||||
op->desc_id.slot < slots_.size() &&
|
||||
slots_[op->desc_id.slot].in_use &&
|
||||
slots_[op->desc_id.slot].id.generation == op->desc_id.generation) {
|
||||
auto& slot = slots_[op->desc_id.slot];
|
||||
if (op->dir == Direction::write && slot.epoll_out_armed) {
|
||||
slot.active_write.reset();
|
||||
sync_epoll_interest_locked(slot);
|
||||
slot.active_write = op;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (executing) {
|
||||
continue; // The syscall's real result settles it (D1).
|
||||
}
|
||||
if (complete_op_and_collect_tickets(
|
||||
op,
|
||||
std::unexpected{make_io_error(IoErrorCode::cancelled, "IO operation cancelled")},
|
||||
tickets,
|
||||
close_waiters)) {
|
||||
close_waiters,
|
||||
/*skip_if_executing=*/true)) {
|
||||
++done;
|
||||
}
|
||||
}
|
||||
@@ -2570,23 +2584,12 @@ private:
|
||||
std::size_t done = 0;
|
||||
std::vector<CloseWaiter> close_waiters;
|
||||
for (const auto& op : expired) {
|
||||
{
|
||||
std::lock_guard lk{mu_};
|
||||
if (!op->retired && op->dir == Direction::write &&
|
||||
op->desc_id.slot < slots_.size() &&
|
||||
slots_[op->desc_id.slot].in_use &&
|
||||
slots_[op->desc_id.slot].id.generation == op->desc_id.generation) {
|
||||
auto& s = slots_[op->desc_id.slot];
|
||||
s.active_write.reset();
|
||||
sync_epoll_interest_locked(s);
|
||||
s.active_write = op;
|
||||
}
|
||||
}
|
||||
if (complete_op_and_collect_tickets(
|
||||
op,
|
||||
std::unexpected{make_io_error(IoErrorCode::timeout, "IO operation timed out")},
|
||||
tickets,
|
||||
close_waiters)) {
|
||||
close_waiters,
|
||||
/*skip_if_executing=*/true)) {
|
||||
++done;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,3 +598,172 @@ Void::Testing::Test bus_flush_blocking_self_join_and_manual_invalid()
|
||||
Void::Testing::require(exec->join().has_value());
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test bus_pumping_self_join_returns_self_join()
|
||||
{
|
||||
using namespace Void::EventBus;
|
||||
Void::Async::ManualExecutor manual;
|
||||
EventBus bus{manual};
|
||||
std::optional<Void::Result::Result<void>> fp_res;
|
||||
std::optional<Void::Result::Result<void>> cj_res;
|
||||
|
||||
auto sub = bus.try_subscribe<Ping>([&](const Ping&) {
|
||||
fp_res = bus.flush_pumping(manual);
|
||||
cj_res = bus.close_and_join_pumping(manual);
|
||||
});
|
||||
Void::Testing::require(sub.has_value());
|
||||
Void::Testing::require(bus.try_publish(Ping{7}).has_value());
|
||||
(void)manual.drain();
|
||||
|
||||
Void::Testing::require(fp_res.has_value() && !fp_res->has_value());
|
||||
Void::Testing::expect_eq(
|
||||
async_code(fp_res->error()),
|
||||
static_cast<std::int32_t>(Void::Async::AsyncErrorCode::self_join));
|
||||
Void::Testing::require(cj_res.has_value() && !cj_res->has_value());
|
||||
Void::Testing::expect_eq(
|
||||
async_code(cj_res->error()),
|
||||
static_cast<std::int32_t>(Void::Async::AsyncErrorCode::self_join));
|
||||
Void::Testing::require(bus.close_and_join_pumping(manual).has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test bus_close_and_join_waits_for_slow_capture_destructor()
|
||||
{
|
||||
using namespace Void::EventBus;
|
||||
struct SlowGuard {
|
||||
explicit SlowGuard(std::atomic<bool>* p) : destroyed(p) {}
|
||||
std::atomic<bool>* destroyed{nullptr};
|
||||
~SlowGuard()
|
||||
{
|
||||
if (destroyed != nullptr) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{15});
|
||||
destroyed->store(true, std::memory_order_release);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 1. ThreadExecutor subscription::close_and_join waits until slow capture dtor finishes.
|
||||
{
|
||||
auto exec_res = Void::Async::ThreadExecutor::create(
|
||||
Void::Async::ThreadExecutorOptions{.workers = 2, .max_admitted = 16});
|
||||
Void::Testing::require(exec_res.has_value());
|
||||
auto exec = std::move(*exec_res);
|
||||
Void::Testing::require(exec->start().has_value());
|
||||
|
||||
EventBus bus{*exec};
|
||||
std::atomic<bool> destroyed{false};
|
||||
std::latch entered{1};
|
||||
std::promise<void> rel;
|
||||
auto rel_fut = rel.get_future().share();
|
||||
auto guard = std::make_shared<SlowGuard>(&destroyed);
|
||||
|
||||
auto sub = bus.try_subscribe<Ping>([&, guard](const Ping&) {
|
||||
(void)guard;
|
||||
entered.count_down();
|
||||
rel_fut.wait();
|
||||
});
|
||||
Void::Testing::require(sub.has_value());
|
||||
guard.reset();
|
||||
|
||||
Void::Testing::require(bus.try_publish(Ping{1}).has_value());
|
||||
entered.wait();
|
||||
|
||||
std::thread releaser([&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
rel.set_value();
|
||||
});
|
||||
Void::Testing::require(sub->close_and_join().has_value());
|
||||
// Must ALREADY be destroyed when close_and_join returns!
|
||||
Void::Testing::expect(destroyed.load(std::memory_order_acquire));
|
||||
releaser.join();
|
||||
|
||||
Void::Testing::require(bus.close_and_join().has_value());
|
||||
exec->close();
|
||||
Void::Testing::require(exec->join().has_value());
|
||||
}
|
||||
|
||||
// 2. Mode::Async EventBus::close_and_join waits until slow capture dtor finishes.
|
||||
{
|
||||
EventBus bus{Mode::Async};
|
||||
std::atomic<bool> destroyed{false};
|
||||
std::latch entered{1};
|
||||
std::promise<void> rel;
|
||||
auto rel_fut = rel.get_future().share();
|
||||
auto guard = std::make_shared<SlowGuard>(&destroyed);
|
||||
|
||||
auto sub = bus.try_subscribe<Ping>([&, guard](const Ping&) {
|
||||
(void)guard;
|
||||
entered.count_down();
|
||||
rel_fut.wait();
|
||||
});
|
||||
Void::Testing::require(sub.has_value());
|
||||
guard.reset();
|
||||
|
||||
bus.publish(Ping{2});
|
||||
entered.wait();
|
||||
|
||||
std::thread releaser([&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
rel.set_value();
|
||||
});
|
||||
Void::Testing::require(bus.close_and_join().has_value());
|
||||
Void::Testing::expect(destroyed.load(std::memory_order_acquire));
|
||||
releaser.join();
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test bus_legacy_async_purged_drop_outside_lock()
|
||||
{
|
||||
using namespace Void::EventBus;
|
||||
struct MuLockingDtor {
|
||||
EventBus* bus{nullptr};
|
||||
std::atomic<bool>* dropped{nullptr};
|
||||
std::atomic<int>* calls{nullptr};
|
||||
~MuLockingDtor()
|
||||
{
|
||||
if (bus != nullptr) {
|
||||
bus->unsubscribe(0); // Acquires BusCore::mu; would deadlock under lock.
|
||||
}
|
||||
if (dropped != nullptr) {
|
||||
dropped->store(true, std::memory_order_release);
|
||||
}
|
||||
if (calls != nullptr) {
|
||||
calls->fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EventBus bus{Mode::Async};
|
||||
std::atomic<bool> dropped{false};
|
||||
std::atomic<int> dtor_calls{0};
|
||||
std::atomic<int> b_ran{0};
|
||||
std::optional<Void::Result::Result<void>> sub_b_join_res;
|
||||
auto sub_b_ptr = std::make_shared<std::optional<EventBus::Subscription>>();
|
||||
|
||||
// Subscribe A before B so run_worker visits A first for the same queued item.
|
||||
auto sub_a = bus.try_subscribe<Ping>([&](const Ping&) {
|
||||
if (*sub_b_ptr) {
|
||||
sub_b_join_res = (*sub_b_ptr)->close_and_join();
|
||||
}
|
||||
});
|
||||
Void::Testing::require(sub_a.has_value());
|
||||
|
||||
{
|
||||
auto guard = std::shared_ptr<MuLockingDtor>(
|
||||
new MuLockingDtor{&bus, &dropped, &dtor_calls});
|
||||
auto sb = bus.try_subscribe<Ping>([&, guard](const Ping&) {
|
||||
(void)guard;
|
||||
b_ran.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
Void::Testing::require(sb.has_value());
|
||||
*sub_b_ptr = std::move(*sb);
|
||||
}
|
||||
|
||||
bus.publish(Ping{1});
|
||||
bus.flush();
|
||||
Void::Testing::require(sub_b_join_res.has_value());
|
||||
Void::Testing::expect(sub_b_join_res->has_value());
|
||||
Void::Testing::expect_eq(b_ran.load(), 0);
|
||||
Void::Testing::expect(dropped.load(std::memory_order_acquire));
|
||||
Void::Testing::expect_eq(dtor_calls.load(), 1);
|
||||
Void::Testing::require(bus.close_and_join().has_value());
|
||||
}
|
||||
@@ -267,3 +267,27 @@ Void::Testing::Test io_pump_until_exits_after_shutdown_complete()
|
||||
require(scope.join_pumping(exec).has_value());
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test io_pump_until_mock_max_wait_paces_idle_turns()
|
||||
{
|
||||
ManualExecutor exec;
|
||||
const auto& clock = Void::Time::SystemMonotonicClock::instance();
|
||||
auto drv_res = Driver::create(
|
||||
exec, BackendOptions{.preference = BackendPreference::mock}, clock);
|
||||
require(drv_res.has_value());
|
||||
Driver& drv = **drv_res;
|
||||
|
||||
auto res = pump_until(
|
||||
drv,
|
||||
exec,
|
||||
[] { return false; },
|
||||
PumpOptions{
|
||||
.max_wait = 5ms,
|
||||
.max_turns = 200,
|
||||
.operation = OperationOptions{.deadline = clock.now() + 20ms},
|
||||
});
|
||||
require(!res.has_value());
|
||||
expect_eq(res.error().code().value,
|
||||
static_cast<std::int32_t>(IoErrorCode::timeout));
|
||||
expect(drv.telemetry().turns < std::uint64_t{100});
|
||||
}
|
||||
@@ -530,3 +530,207 @@ Void::Testing::Test io_run_busy_and_mock_wait_does_not_spin()
|
||||
expect(drv.telemetry().turns < 50);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test io_shutdown_epoll_idle_readable_fd_no_busy_spin()
|
||||
{
|
||||
ManualExecutor exec;
|
||||
auto drv_res = Driver::create(
|
||||
exec, BackendOptions{.preference = BackendPreference::epoll});
|
||||
require(drv_res.has_value());
|
||||
Driver& drv = **drv_res;
|
||||
|
||||
auto pair_res = drv.create_socket_pair();
|
||||
require(pair_res.has_value());
|
||||
ByteStream a = std::move(pair_res->first);
|
||||
ByteStream b = std::move(pair_res->second);
|
||||
|
||||
// Push unread data into stream `a` while NO read operation is pending on `a`.
|
||||
TaskScope scope{exec};
|
||||
const std::array<std::byte, 4> msg{
|
||||
std::byte{'p'}, std::byte{'i'}, std::byte{'n'}, std::byte{'g'}};
|
||||
std::optional<Void::Result::Result<Transfer>> wres;
|
||||
auto wtask = [](ByteStream* st,
|
||||
std::span<const std::byte> sp,
|
||||
std::optional<Void::Result::Result<Transfer>>* out)
|
||||
-> Void::Coro::Task<void> { *out = co_await st->write_some(sp); };
|
||||
require(scope.spawn(wtask(&b, msg, &wres)).has_value());
|
||||
(void)exec.drain();
|
||||
while (!wres.has_value()) {
|
||||
(void)drv.poll_once(1ms);
|
||||
(void)exec.drain();
|
||||
}
|
||||
require(wres->has_value());
|
||||
expect_eq((*wres)->bytes, std::size_t{4});
|
||||
|
||||
// Running driver with unread data on `a` and no active reader must NOT busy-spin.
|
||||
std::stop_source stop;
|
||||
Void::Result::Result<std::size_t> run_res{std::size_t{0}};
|
||||
std::thread runner([&]() { run_res = drv.run(stop.get_token(), 10ms); });
|
||||
std::this_thread::sleep_for(40ms);
|
||||
stop.request_stop();
|
||||
runner.join();
|
||||
|
||||
require(run_res.has_value());
|
||||
expect(drv.telemetry().turns <= std::uint64_t{15});
|
||||
|
||||
auto rep = drv.shutdown(OperationOptions{});
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
require(scope.join_pumping(exec).has_value());
|
||||
(void)a;
|
||||
}
|
||||
|
||||
Void::Testing::Test io_shutdown_mock_try_acquire_race_tsan()
|
||||
{
|
||||
// 1. try_acquire_read refuses once stream close or driver shutdown begins.
|
||||
{
|
||||
ManualExecutor exec;
|
||||
auto drv_res = Driver::create(
|
||||
exec, BackendOptions{.preference = BackendPreference::mock});
|
||||
require(drv_res.has_value());
|
||||
Driver& drv = **drv_res;
|
||||
auto* ctrl = drv.mock_controller();
|
||||
require(ctrl != nullptr);
|
||||
|
||||
auto s_res = drv.create_mock_stream();
|
||||
require(s_res.has_value());
|
||||
ByteStream s = std::move(*s_res);
|
||||
|
||||
std::array<std::byte, 8> buf{};
|
||||
std::optional<Void::Result::Result<Transfer>> rres;
|
||||
TaskScope scope{exec};
|
||||
auto rtask = [](ByteStream* st,
|
||||
std::span<std::byte> sp,
|
||||
std::optional<Void::Result::Result<Transfer>>* out)
|
||||
-> Void::Coro::Task<void> { *out = co_await st->read_some(sp); };
|
||||
require(scope.spawn(rtask(&s, buf, &rres)).has_value());
|
||||
(void)exec.drain();
|
||||
|
||||
std::optional<Void::Result::Result<void>> cres;
|
||||
auto ctask = [](ByteStream* st,
|
||||
std::optional<Void::Result::Result<void>>* out)
|
||||
-> Void::Coro::Task<void> { *out = co_await st->close_and_join(); };
|
||||
require(scope.spawn(ctask(&s, &cres)).has_value());
|
||||
(void)exec.drain();
|
||||
|
||||
expect(!ctrl->try_acquire_read(s).has_value());
|
||||
(void)drv.poll_once(0ns);
|
||||
require(scope.join_pumping(exec).has_value());
|
||||
auto rep = drv.shutdown(OperationOptions{});
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
}
|
||||
|
||||
// 2. Concurrent race between try_acquire_read and stop_requested cancellation (TSan).
|
||||
{
|
||||
ManualExecutor exec;
|
||||
auto drv_res = Driver::create(
|
||||
exec, BackendOptions{.preference = BackendPreference::mock});
|
||||
require(drv_res.has_value());
|
||||
Driver& drv = **drv_res;
|
||||
auto* ctrl = drv.mock_controller();
|
||||
require(ctrl != nullptr);
|
||||
|
||||
auto s_res = drv.create_mock_stream();
|
||||
require(s_res.has_value());
|
||||
ByteStream s = std::move(*s_res);
|
||||
|
||||
const std::array<std::byte, 2> payload{std::byte{'o'}, std::byte{'k'}};
|
||||
for (int iter = 0; iter < 30; ++iter) {
|
||||
std::array<std::byte, 8> buf{};
|
||||
std::optional<Void::Result::Result<Transfer>> rres;
|
||||
std::stop_source stop_src;
|
||||
TaskScope scope{exec};
|
||||
auto rtask = [](ByteStream* st,
|
||||
std::span<std::byte> sp,
|
||||
std::stop_token tok,
|
||||
std::optional<Void::Result::Result<Transfer>>* out)
|
||||
-> Void::Coro::Task<void> {
|
||||
*out = co_await st->read_some(sp, OperationOptions{.stop = tok});
|
||||
};
|
||||
require(scope.spawn(rtask(&s, buf, stop_src.get_token(), &rres)).has_value());
|
||||
(void)exec.drain();
|
||||
|
||||
std::atomic<bool> finish_ok{true};
|
||||
std::thread finisher([&]() {
|
||||
if (auto tok = ctrl->try_acquire_read(s)) {
|
||||
finish_ok.store(
|
||||
ctrl->finish_read_data(*tok, payload, false),
|
||||
std::memory_order_release);
|
||||
}
|
||||
});
|
||||
std::thread canceller([&]() {
|
||||
stop_src.request_stop();
|
||||
(void)drv.poll_once(0ns);
|
||||
});
|
||||
finisher.join();
|
||||
canceller.join();
|
||||
expect(finish_ok.load(std::memory_order_acquire));
|
||||
(void)drv.poll_once(0ns);
|
||||
require(scope.join_pumping(exec).has_value());
|
||||
|
||||
require(rres.has_value());
|
||||
if (rres->has_value()) {
|
||||
expect_eq((*rres)->bytes, std::size_t{2});
|
||||
} else {
|
||||
expect_eq(rres->error().code().value,
|
||||
static_cast<std::int32_t>(IoErrorCode::cancelled));
|
||||
}
|
||||
}
|
||||
auto rep = drv.shutdown(OperationOptions{});
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
}
|
||||
|
||||
// 3. Concurrent race between try_acquire_read and Driver::shutdown (TSan).
|
||||
for (int iter = 0; iter < 15; ++iter) {
|
||||
ManualExecutor exec;
|
||||
auto drv_res = Driver::create(
|
||||
exec, BackendOptions{.preference = BackendPreference::mock});
|
||||
require(drv_res.has_value());
|
||||
Driver& drv = **drv_res;
|
||||
auto* ctrl = drv.mock_controller();
|
||||
require(ctrl != nullptr);
|
||||
|
||||
auto s_res = drv.create_mock_stream();
|
||||
require(s_res.has_value());
|
||||
ByteStream s = std::move(*s_res);
|
||||
|
||||
std::array<std::byte, 8> buf{};
|
||||
std::optional<Void::Result::Result<Transfer>> rres;
|
||||
TaskScope scope{exec};
|
||||
auto rtask = [](ByteStream* st,
|
||||
std::span<std::byte> sp,
|
||||
std::optional<Void::Result::Result<Transfer>>* out)
|
||||
-> Void::Coro::Task<void> { *out = co_await st->read_some(sp); };
|
||||
require(scope.spawn(rtask(&s, buf, &rres)).has_value());
|
||||
(void)exec.drain();
|
||||
|
||||
const std::array<std::byte, 2> payload{std::byte{'o'}, std::byte{'k'}};
|
||||
std::atomic<bool> finish_ok{true};
|
||||
std::thread finisher([&]() {
|
||||
if (auto tok = ctrl->try_acquire_read(s)) {
|
||||
finish_ok.store(
|
||||
ctrl->finish_read_data(*tok, payload, false),
|
||||
std::memory_order_release);
|
||||
}
|
||||
});
|
||||
std::optional<Void::Result::Result<DriverShutdownReport>> sd_rep;
|
||||
std::thread shutdowner([&]() {
|
||||
sd_rep = drv.shutdown(OperationOptions{});
|
||||
});
|
||||
finisher.join();
|
||||
shutdowner.join();
|
||||
expect(finish_ok.load(std::memory_order_acquire));
|
||||
require(sd_rep.has_value() && sd_rep->has_value());
|
||||
expect((*sd_rep)->complete);
|
||||
require(scope.join_pumping(exec).has_value());
|
||||
require(rres.has_value());
|
||||
if (rres->has_value()) {
|
||||
expect_eq((*rres)->bytes, std::size_t{2});
|
||||
} else {
|
||||
expect_eq(rres->error().code().value,
|
||||
static_cast<std::int32_t>(IoErrorCode::closed));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <Void/Async/Executor.hpp>
|
||||
#include <Void/Async/Task.hpp>
|
||||
#include <Void/Async/ThreadExecutor.hpp>
|
||||
#include <Void/Async/Timer.hpp>
|
||||
#include <Void/IO/Driver.hpp>
|
||||
#include <Void/IO/File.hpp>
|
||||
@@ -939,3 +940,93 @@ Void::Testing::Test runtime_destructor_blocks_until_complete_after_incomplete_sh
|
||||
expect(task_finished.load(std::memory_order_acquire));
|
||||
expect_eq(wait_for_task_count(baseline), baseline);
|
||||
}
|
||||
|
||||
Void::Testing::Test runtime_embedded_manual_poll_shutdown_completes_exporter()
|
||||
{
|
||||
ManualExecutor manual;
|
||||
Void::Time::ManualClock clock;
|
||||
auto drv_res = Void::IO::Driver::create(
|
||||
manual,
|
||||
Void::IO::BackendOptions{.preference = Void::IO::BackendPreference::mock},
|
||||
clock);
|
||||
require(drv_res.has_value());
|
||||
|
||||
auto exp = std::make_shared<CompletionProbeComponent>();
|
||||
HostBuilder builder;
|
||||
builder.with_embedded(EmbeddedResources{
|
||||
.executor = &manual,
|
||||
.io = drv_res->get(),
|
||||
.clock = &clock,
|
||||
});
|
||||
require(builder.add_component("exp", ResourceKind::exporter, exp).has_value());
|
||||
|
||||
auto host_res = builder.build();
|
||||
require(host_res.has_value());
|
||||
Host host = std::move(*host_res);
|
||||
require(host.start().has_value());
|
||||
|
||||
std::optional<ShutdownReport> rep;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
auto pr = host.poll_shutdown();
|
||||
require(pr.has_value());
|
||||
rep = *pr;
|
||||
if (rep->complete) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
expect(rep->state == HostState::stopped);
|
||||
expect(exp->stop_ran.load(std::memory_order_acquire));
|
||||
}
|
||||
|
||||
Void::Testing::Test runtime_embedded_thread_executor_shutdown_blocking_succeeds()
|
||||
{
|
||||
const std::size_t baseline = settle_baseline_tasks();
|
||||
auto exec_res = Void::Async::ThreadExecutor::create(
|
||||
Void::Async::ThreadExecutorOptions{.workers = 2, .max_admitted = 32});
|
||||
require(exec_res.has_value());
|
||||
auto exec = std::move(*exec_res);
|
||||
require(exec->start().has_value());
|
||||
|
||||
auto drv_res = Void::IO::Driver::create(
|
||||
*exec,
|
||||
Void::IO::BackendOptions{.preference = Void::IO::BackendPreference::mock});
|
||||
require(drv_res.has_value());
|
||||
|
||||
auto svc = std::make_shared<CompletionProbeComponent>();
|
||||
std::atomic<bool> task_done{false};
|
||||
{
|
||||
HostBuilder builder;
|
||||
builder.with_embedded(EmbeddedResources{
|
||||
.executor = exec.get(),
|
||||
.io = drv_res->get(),
|
||||
});
|
||||
require(builder.add_component("svc", ResourceKind::service, svc).has_value());
|
||||
|
||||
auto host_res = builder.build();
|
||||
require(host_res.has_value());
|
||||
Host host = std::move(*host_res);
|
||||
require(host.start().has_value());
|
||||
|
||||
auto jh = host.spawn(quick_done_task(&task_done));
|
||||
require(jh.has_value());
|
||||
|
||||
auto rep = host.shutdown_blocking();
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
expect(rep->state == HostState::stopped);
|
||||
}
|
||||
|
||||
expect(task_done.load(std::memory_order_acquire));
|
||||
expect(svc->stop_ran.load(std::memory_order_acquire));
|
||||
expect(!(*drv_res)->shutdown_complete());
|
||||
expect(exec->try_reserve_slot().has_value());
|
||||
exec->release_reserved();
|
||||
|
||||
auto drep = (*drv_res)->shutdown(OperationOptions{});
|
||||
require(drep.has_value() && drep->complete);
|
||||
exec->close();
|
||||
require(exec->join().has_value());
|
||||
expect_eq(wait_for_task_count(baseline), baseline);
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <latch>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -692,3 +693,81 @@ Void::Testing::Test runtime_moved_from_host_safe_defaults()
|
||||
|
||||
h1.begin_shutdown();
|
||||
}
|
||||
|
||||
Void::Testing::Test runtime_begin_shutdown_during_start_prevents_ready()
|
||||
{
|
||||
const std::size_t baseline = settle_baseline_tasks();
|
||||
Options opts;
|
||||
opts.cpu_workers = 1;
|
||||
opts.file_workers = 1;
|
||||
opts.io.preference = Void::IO::BackendPreference::mock;
|
||||
|
||||
auto host_res = Host::create(opts);
|
||||
require(host_res.has_value());
|
||||
Host host = std::move(*host_res);
|
||||
|
||||
bool invoked = false;
|
||||
auto sr = host.start(StartOptions{
|
||||
.before_step = [&](StartStep step) -> Void::Result::Result<void> {
|
||||
if (step == StartStep::components && !invoked) {
|
||||
invoked = true;
|
||||
std::thread t([&]() { host.begin_shutdown(); });
|
||||
t.join();
|
||||
}
|
||||
return {};
|
||||
},
|
||||
});
|
||||
require(sr.has_value());
|
||||
expect(invoked);
|
||||
expect(!host.is_ready());
|
||||
expect(host.state() == HostState::stopping_admission);
|
||||
|
||||
std::atomic<bool> flag{false};
|
||||
auto spw = host.spawn(set_flag_task(&flag));
|
||||
expect(!spw.has_value());
|
||||
expect(spw.error() == Void::Async::AdmissionError::stopped);
|
||||
|
||||
auto rep = host.shutdown_blocking();
|
||||
require(rep.has_value());
|
||||
expect(rep->complete);
|
||||
expect(rep->state == HostState::stopped);
|
||||
expect_eq(wait_for_task_count(baseline), baseline);
|
||||
}
|
||||
|
||||
Void::Testing::Test runtime_concurrent_shutdown_waits_for_start_tsan()
|
||||
{
|
||||
const std::size_t baseline = settle_baseline_tasks();
|
||||
Options opts;
|
||||
opts.cpu_workers = 1;
|
||||
opts.file_workers = 1;
|
||||
opts.io.preference = Void::IO::BackendPreference::mock;
|
||||
|
||||
auto host_res = Host::create(opts);
|
||||
require(host_res.has_value());
|
||||
Host host = std::move(*host_res);
|
||||
|
||||
std::latch entered_components{1};
|
||||
std::optional<Void::Result::Result<Void::Runtime::ShutdownReport>> sd_res;
|
||||
std::thread stopper([&]() {
|
||||
entered_components.wait();
|
||||
sd_res = host.shutdown_blocking();
|
||||
});
|
||||
|
||||
auto sr = host.start(StartOptions{
|
||||
.before_step = [&](StartStep step) -> Void::Result::Result<void> {
|
||||
if (step == StartStep::components) {
|
||||
entered_components.count_down();
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
return {};
|
||||
},
|
||||
});
|
||||
stopper.join();
|
||||
|
||||
require(sr.has_value());
|
||||
require(sd_res.has_value() && sd_res->has_value());
|
||||
expect((*sd_res)->complete);
|
||||
expect(host.state() == HostState::stopped);
|
||||
expect(!host.is_ready());
|
||||
expect_eq(wait_for_task_count(baseline), baseline);
|
||||
}
|
||||
Reference in new issue
Block a user