Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.Sleep can block VERY long time, when drift the clock backwards #39

Open
errpunk opened this issue Mar 13, 2023 · 2 comments
Open

Comments

@errpunk
Copy link

errpunk commented Mar 13, 2023

in this scenario, NextID() could block very long time.

  1. in a high load: (sf.sequence + 1) & maskSequence == 0
  2. in the same time, system clock drift backwards, say 8 hours

this will block the function for 8 hour.

can we use some kind of Monotonic time or add a new function with timeout-control to avoid this?

@YoshiyukiMineo
Copy link
Member

By the slew mode of NTP service, you can prevent the system clock from stepping backward.

@errpunk
Copy link
Author

errpunk commented May 6, 2023

Thank you for your response. The NTP slew mode is indeed a good solution, but it cannot be used in the following scenarios:

  • Some edge devices that are offline, frequently unreachable, and unmonitored for long periods of time, such as edge servers and IoT devices.
  • Devices that cannot use the NTP protocol due to security requirements.

My use case happens to be some remote, unattended edge devices that can only be blocked when problems occur.

The Go language's built-in time.Time type uses the mechanism of monotonic time to avoid time drift when calculating time differences. My colleague will provide a PR to demonstrate this solution. I hope you can take some time to review it.

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

No branches or pull requests

2 participants