fix(timer): resolve service safely and add executor constructors#280
Conversation
|
An automated preview of the documentation is available at https://280.corosio.prtest3.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-06-17 18:43:53 UTC |
|
GCOVR code coverage report https://280.corosio.prtest3.cppalliance.org/gcovr/index.html Build time: 2026-06-17 18:55:20 UTC |
Fix UB in the timer constructor (cppalliance#213). The old timer_service_direct did an unchecked static_cast<io_context&> on a capy::execution_context and dereferenced io_context::timer_svc_, so constructing a timer from any non-io_context (a plain execution_context, a thread_pool, or a user-derived context) read memory at a bogus offset and crashed. Resolve the timer service through the shared io_object::create_handle<timer_service>() path that every other I/O object uses; it throws std::logic_error when the service is absent. Delete the bespoke timer_service_direct helper along with the now-dead timer_service_access struct and io_context::timer_svc_ cache. Bring timer in line with the other public I/O objects (cppalliance#231): add executor constructors to both timer and native_timer (Ex const&; Ex const&, time_point; Ex const&, duration), mirroring the tcp_acceptor/signal_set shape and delegating to the executor's context. For the owning cancel_after/cancel_at path the timer is built inside a noexcept await_suspend from the awaiting coroutine's executor context. A non-io_context executor cannot supply a timer; rather than silently running the operation with no deadline, translate the failure into a clear precondition diagnostic (which aborts by design) and document the requirement on the owning overloads. Tighten timer_service.hpp to include detail/scheduler.hpp directly instead of pulling it transitively through io_context.hpp. Add tests for the throw path and for the new executor constructors.
a5e1a29 to
0396347
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #280 +/- ##
===========================================
- Coverage 77.69% 77.68% -0.01%
===========================================
Files 96 96
Lines 7188 7185 -3
Branches 1753 1751 -2
===========================================
- Hits 5585 5582 -3
Misses 1099 1099
Partials 504 504
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Fix UB in the timer constructor (#213). The old timer_service_direct did an unchecked static_cast<io_context&> on a capy::execution_context and dereferenced io_context::timer_svc_, so constructing a timer from any non-io_context (a plain execution_context, a thread_pool, or a user-derived context) read memory at a bogus offset and crashed. Resolve the timer service through the shared io_object::create_handle<timer_service>() path that every other I/O object uses; it throws std::logic_error when the service is absent. Delete the bespoke timer_service_direct helper along with the now-dead timer_service_access struct and io_context::timer_svc_ cache.
Bring timer in line with the other public I/O objects (#231): add executor constructors to both timer and native_timer (Ex const&; Ex const&, time_point; Ex const&, duration), mirroring the tcp_acceptor/signal_set shape and delegating to the executor's context.
For the owning cancel_after/cancel_at path the timer is built inside a noexcept await_suspend from the awaiting coroutine's executor context. A non-io_context executor cannot supply a timer; rather than silently running the operation with no deadline, translate the failure into a clear precondition diagnostic (which aborts by design) and document the requirement on the owning overloads.
Tighten timer_service.hpp to include detail/scheduler.hpp directly instead of pulling it transitively through io_context.hpp.
Add tests for the throw path and for the new executor constructors.
Closes #213