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

Avoid large exponents in BackoffMachine #1339

Open
PIG208 opened this issue Feb 7, 2025 · 2 comments · May be fixed by #1352
Open

Avoid large exponents in BackoffMachine #1339

PIG208 opened this issue Feb 7, 2025 · 2 comments · May be fixed by #1352
Labels
a-api Implementing specific parts of the Zulip server API a-sync Event queue; retry; local echo; races

Comments

@PIG208
Copy link
Member

PIG208 commented Feb 7, 2025

  Future<void> wait() async {
    final bound = _minDuration(maxBound,
                               firstBound * pow(base, _waitsCompleted));
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Unsupported operation: Infinity or NaN toInt
#0      double.round (dart:core-patch/double.dart)
#1      Duration.* (dart:core/duration.dart:213:56)
#2      BackoffMachine.wait (package:zulip/api/backoff.dart:87:43)
#3      UpdateMachine._registerQueueWithRetry (package:zulip/model/store.dart:930:53)
<asynchronous suspension>
#4      UpdateMachine.load (package:zulip/model/store.dart:875:29)
<asynchronous suspension>
#5      LiveGlobalStore.doLoadPerAccount (package:zulip/model/store.dart:816:27)

What might have happened here is that _waitsCompleted gets to a large enough value that pow(base, _waitsCompleted) becomes either infinity or NaN.

Proposed fix by Greg:

  • Instead of only _waitsCompleted, have also a (private) field equivalent to that bound local.
  • Then at each iteration, multiply that by base and apply _minDuration.
  • That way there's no pow (especially none with a potentially-large argument), and no giant numbers as intermediates in the calculation.

CZO discussion

@PIG208 PIG208 added a-api Implementing specific parts of the Zulip server API a-sync Event queue; retry; local echo; races labels Feb 7, 2025
@PIG208 PIG208 added this to the M6: Post-launch milestone Feb 7, 2025
@ajayrajsaini
Copy link

hi @PIG208,
i will love contribute to this issue, if it is still open

@suraj-aayush
Copy link

suraj-aayush commented Feb 13, 2025

Hi @PIG208
I would like to work on this issue. Can you please assign it to me?
I have set up and corrected the code.

My Code:
Fixes incorrect backoff logic – Now, _currentBound correctly increases exponentially.
Prevents exceeding maxBound – Ensures we don’t wait longer than necessary.
Improves reliability – Makes sure backoff logic works consistently across retries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-api Implementing specific parts of the Zulip server API a-sync Event queue; retry; local echo; races
Projects
Status: No status
3 participants