Skip to content

Commit e56eb71

Browse files
committed
Fix timerfd handling in epoll reactor
- Consume timerfd on expiry to prevent epoll busy-spinning (level-triggered fd must be read to clear readable state) - Remove last_timerfd_expiry_ caching optimization to match Asio (eliminates data race between timer callback and reactor thread)
1 parent f689216 commit e56eb71

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

‎src/corosio/src/detail/epoll/scheduler.cpp‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,6 @@ update_timerfd() const
588588
{
589589
auto nearest = timer_svc_->nearest_expiry();
590590

591-
// Skip syscall if expiry hasn't changed
592-
if (nearest == last_timerfd_expiry_)
593-
return;
594-
595-
last_timerfd_expiry_ = nearest;
596-
597591
itimerspec ts{};
598592
int flags = 0;
599593

@@ -659,6 +653,8 @@ run_reactor(std::unique_lock<std::mutex>& lock)
659653

660654
if (events[i].data.ptr == &timer_fd_)
661655
{
656+
std::uint64_t expirations;
657+
[[maybe_unused]] auto r = ::read(timer_fd_, &expirations, sizeof(expirations));
662658
check_timers = true;
663659
continue;
664660
}

‎src/corosio/src/detail/epoll/scheduler.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ class epoll_scheduler
167167
// Edge-triggered eventfd state
168168
mutable std::atomic<bool> eventfd_armed_{false};
169169

170-
// Track last timerfd expiry to avoid redundant timerfd_settime calls
171-
mutable timer_service::time_point last_timerfd_expiry_{timer_service::time_point::max()};
172170

173171
// Sentinel operation for interleaving reactor runs with handler execution.
174172
// Ensures the reactor runs periodically even when handlers are continuously

0 commit comments

Comments
 (0)