contrib/timer-wheel: fix always-false idx < 0 comparison - #4773
Open
ThalesBarretto wants to merge 1 commit into
Open
contrib/timer-wheel: fix always-false idx < 0 comparison#4773ThalesBarretto wants to merge 1 commit into
ThalesBarretto wants to merge 1 commit into
Conversation
__gf_tw_add_timer() classifies a timer by idx = expires - timer_sec, where idx is unsigned long. The branch handling an expiry already in the past tests "idx < 0", always false for an unsigned value: the compiler warns (-Wtype-limits) and the branch is dead, so a past/now expiry is misfiled into tv5 instead of firing promptly from tv1. The wheel is a port of the pre-4.8 Linux kernel cascading timer wheel, whose __internal_add_timer() uses "(signed long) idx < 0" to detect the unsigned wrap. The port dropped the cast; restore it. No functional change for current callers: every insert path adds timer_sec first, so idx >= 0 in practice. The fix silences the warning and restores the past-expiry safety net. Fixes: gluster#4770 Signed-off-by: Thales Antunes de Oliveira Barretto <thales.barretto.git@gmail.com>
amarts
approved these changes
Sep 11, 2026
ThalesBarretto
marked this pull request as ready for review
September 11, 2026 12:40
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.
Restores the
(signed long)cast the pre-4.8 Linux cascading timer-wheel port dropped, sothe past-expiry branch in
__gf_tw_add_timer()is live again.idxisunsigned long, soidx < 0is always false (-Wtype-limits): a timer whoseexpiry is already past /
== now(idxwrapped nearULONG_MAX) misses all four sizebuckets and falls through to
tv5instead oftv1.Latent for current callers — every insert path adds
base->timer_secfirst, soidx >= 0in practice — so this silences the warning and restores the intended safety net rather than
fixing an observed misfire. One line:
idx < 0->(long)idx < 0, matching the kernel's__internal_add_timer().Fixes: #4770
Draft for discussion.