Skip to content

feat: change reconnection timer implementation unix time -> cpu clock time#3182

Merged
sfeilmeier merged 2 commits intoOpenEMS:developfrom
girasolenergy:feature/monotonic-timer-for-reconnection
Aug 23, 2025
Merged

feat: change reconnection timer implementation unix time -> cpu clock time#3182
sfeilmeier merged 2 commits intoOpenEMS:developfrom
girasolenergy:feature/monotonic-timer-for-reconnection

Conversation

@miettal
Copy link
Copy Markdown
Contributor

@miettal miettal commented Jun 11, 2025

Currently reconnection timer use unix timestamp and it feed from system. But this time is not monotonic increasing, So there is possibility of time go away to far future, in this case the timer doesn't work correctly. Especially, In case of use RTC and edge is in booting time, If System recoginize wrong time, Sometime edge set wrong timer period and wait forever. // Actually We face this problem recently.

This change provice to use monotonic timer it based on cpu clock to resolve ↑ problem.
Cpu clock has no external dependencies and It suitable reconnection timer use.

Co-author: @cvabc, claude code, chatgpt codex, github copilot

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3182      +/-   ##
=============================================
+ Coverage      58.84%   58.84%   +0.01%     
  Complexity       173      173              
=============================================
  Files           2619     2619              
  Lines         113026   113026              
  Branches        8317     8317              
=============================================
+ Hits           66499    66502       +3     
+ Misses         44038    44033       -5     
- Partials        2489     2491       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@miettal miettal marked this pull request as ready for review June 11, 2025 15:09
Copy link
Copy Markdown
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

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

Looks good. Sorry, I did not find time to review earlier. Now it has to be rebased to current develop.

this.parent = parent;
this.config = config;
this.minWaitSecondsBetweenRetries = new Random().nextInt(config.maxWaitSeconds()) + config.minWaitSeconds();
this.lastTry = System.nanoTime() - this.minWaitSecondsBetweenRetries * 1_000_000_000L;
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.

1_000_000_000L seems arbitrary. Can we not set lastTry to zero instead?

miettal and others added 2 commits August 4, 2025 07:59
… time.

Currently reconnection timer use unix timestamp and it feed from system.
But this time is not motonic increasing, So there is possibility of time
go away to far future, in this case the timer doesn't work correctly.
Especially, In case of use RTC and edge is in booting time, If System
recoginize wrong time, Sometime edge set wrong timer period and wait forever.
// Actually We face this problem recently.

This change provice to use monotonic timer it based on cpu clock to
resolve ↑ problem.
Cpu clock has no external dependencies and It suitable reconnection
timer use.

Co-author: @cvabc, claude code, chatgpt codex, github copilot
@cvabc cvabc force-pushed the feature/monotonic-timer-for-reconnection branch from 09b9741 to 817cad1 Compare August 4, 2025 00:36
@miettal miettal requested a review from sfeilmeier August 14, 2025 07:30
Copy link
Copy Markdown
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

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

Thank you again!

@sfeilmeier sfeilmeier merged commit 22530f4 into OpenEMS:develop Aug 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants