Skip to content

Fix idle-check race aborting a connection that just received data (#5486)#5683

Open
pepone wants to merge 1 commit into
zeroc-ice:mainfrom
pepone:fix/5486-idle-race
Open

Fix idle-check race aborting a connection that just received data (#5486)#5683
pepone wants to merge 1 commit into
zeroc-ice:mainfrom
pepone:fix/5486-idle-race

Conversation

@pepone

@pepone pepone commented Jun 23, 2026

Copy link
Copy Markdown
Member

Addresses #5486 (item 11). One of a set of PRs splitting the grouped transport audit.

ConnectionI::idleCheck aborted the connection whenever the idle timer task fired, even when the IO thread had rescheduled that one-shot task (because fresh bytes arrived) while the fired task was waiting for the connection mutex. idleCheck now skips the abort when the idle check task is still scheduled, mirroring the guard already used by inactivityCheck. Adds IdleTimeoutTransceiverDecorator::idleCheckScheduled().

The race sub-window isn't deterministically testable; Ice/idleTimeout passes with no regression. Codex-audited (no deadlock / lock-order inversion).

ConnectionI::idleCheck aborted the connection whenever the idle timer
task fired, even when the IO thread had rescheduled that one-shot task
(because fresh bytes arrived) while the fired task was waiting for the
connection mutex. idleCheck now skips the abort when the idle check task
is still scheduled, mirroring the guard already used by inactivityCheck.
Adds IdleTimeoutTransceiverDecorator::idleCheckScheduled().

Addresses zeroc-ice#5486 (item 11).
Copilot AI review requested due to automatic review settings June 23, 2026 12:52
@pepone pepone added the cpp label Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes a race in ConnectionI::idleCheck where a fired idle timer task could abort an active connection even if new data arrived and the IO thread rescheduled the idle check while the fired task was blocked on the connection mutex.

Changes:

  • Add IdleTimeoutTransceiverDecorator::idleCheckScheduled() to query whether the idle-check timer task is currently scheduled.
  • Guard ConnectionI::idleCheck to skip aborting when the idle-check task has been rescheduled while waiting for _mutex.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cpp/src/Ice/IdleTimeoutTransceiverDecorator.h Exposes idleCheckScheduled() to detect rescheduling of the idle timer task.
cpp/src/Ice/ConnectionI.cpp Uses the scheduled-state guard to avoid aborting due to an already-rescheduled idle check.

Comment on lines 2292 to +2297
std::lock_guard lock(_mutex);
if (_state == StateActive && _idleTimeoutTransceiver->idleCheckEnabled())
// Skip the abort if the idle check timer task was rescheduled (because we received bytes) while this
// fired task was waiting for _mutex. This mirrors the guard in inactivityCheck and closes the race where
// Timer::run dequeues the one-shot task before invoking it.
if (_state == StateActive && _idleTimeoutTransceiver->idleCheckEnabled() &&
!_idleTimeoutTransceiver->idleCheckScheduled())
void setBufferSize(int rcvSize, int sndSize) final { _decoratee->setBufferSize(rcvSize, sndSize); }

[[nodiscard]] bool idleCheckEnabled() const noexcept { return _idleCheckEnabled; }
[[nodiscard]] bool idleCheckScheduled() const noexcept { return _timer->isScheduled(_idleCheckTimerTask); }
Comment on lines +2296 to +2297
if (_state == StateActive && _idleTimeoutTransceiver->idleCheckEnabled() &&
!_idleTimeoutTransceiver->idleCheckScheduled())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants