Fix clock thread spinning at midnight due to missing tm_mday increment#369
Open
jamesmulcahy wants to merge 1 commit intoNSPManager:develfrom
Open
Fix clock thread spinning at midnight due to missing tm_mday increment#369jamesmulcahy wants to merge 1 commit intoNSPManager:develfrom
jamesmulcahy wants to merge 1 commit intoNSPManager:develfrom
Conversation
When the publish_time_and_date loop crossed midnight, tm_hour was reset to 0 but tm_mday was never incremented. The subsequent mktime call then normalised the struct to midnight of the *current* day (already in the past), so sleep_until returned immediately. The thread would spin an extra iteration around midnight, publishing the date message twice in quick succession before recovering on the next pass. The existing manual month/year rollover check (tm_mday >= 32) was also incorrect: it would miss month boundaries for February and months with 30 days, since it never incremented tm_mday in the first place. Fix: increment tm_mday and remove the manual rollover logic. mktime is specified by the C standard to normalise out-of-range struct tm fields (e.g. January 32 → February 1, month 12 → January of next year) and is leap-year-aware, so calling it already on the next line is sufficient. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
|
Thanks for this. I've spent a bit of time on this issues a few times but never quite got it to work as I wanted. Need to verify that it works as expected at midnight but should be fine as far as I understand it. |
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.
Summary
publish_time_and_datenever incrementedtm_mdaywhen crossing midnight, somktimenormalised the struct back to midnight of the current day (already in the past) — causingsleep_untilto return immediately and the date message to be published twice in quick succession each night before recoveringtm_mday >= 32) was unreachable dead code (tm_mday was never incremented) and would have been wrong anyway for February and 30-day monthstm_mdayand remove the manual rollover logic;mktimeis C-standard-specified to normalise out-of-rangestruct tmfields (e.g. January 32 → February 1, month 12 → January of next year) including leap-year-aware February, and is already called on the very next lineTest plan
🤖 Generated with Claude Code