Fix idle-check race aborting a connection that just received data (#5486)#5683
Open
pepone wants to merge 1 commit into
Open
Fix idle-check race aborting a connection that just received data (#5486)#5683pepone wants to merge 1 commit into
pepone wants to merge 1 commit into
Conversation
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).
Contributor
There was a problem hiding this comment.
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::idleCheckto 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #5486 (item 11). One of a set of PRs splitting the grouped transport audit.
ConnectionI::idleCheckaborted 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.idleChecknow skips the abort when the idle check task is still scheduled, mirroring the guard already used byinactivityCheck. AddsIdleTimeoutTransceiverDecorator::idleCheckScheduled().The race sub-window isn't deterministically testable;
Ice/idleTimeoutpasses with no regression. Codex-audited (no deadlock / lock-order inversion).