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

proxy: div by zero #4845

Merged
merged 4 commits into from
Jul 31, 2023
Merged

proxy: div by zero #4845

merged 4 commits into from
Jul 31, 2023

Conversation

conradludgate
Copy link
Contributor

@conradludgate conradludgate commented Jul 31, 2023

Problem

  1. In the CacheInvalid state loop, we weren't checking the num_retries. If this managed to get up to 32, the retry_after procedure would compute 2^32 which would overflow to 0 and trigger a div by zero
  2. When fixing the above, I started working on a flow diagram for the state machine logic and realised it was more complex than it had to be:
    a. We start in a Cached state
    b. Cached: call connect_once. After the first connect_once error, we always move to the CacheInvalid state, otherwise, we return the connection.
    c. CacheInvalid: we attempt to wake_compute and we either switch to Cached or we retry this step (or we error).
    d. Cached: call connect_once. We either retry this step or we have a connection (or we error) - After num_retries > 1 we never switch back to CacheInvalid.

Summary of changes

  1. Insert a num_retries check in the handle_try_wake procedure. Also using floats in the retry_after procedure to prevent the overflow entirely
  2. Refactor connect_to_compute to be more linear in design.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@conradludgate conradludgate requested a review from a team as a code owner July 31, 2023 10:22
@conradludgate conradludgate requested review from chaporgin and removed request for a team July 31, 2023 10:22
@conradludgate conradludgate enabled auto-merge (squash) July 31, 2023 10:22
@conradludgate conradludgate disabled auto-merge July 31, 2023 10:32
proxy/src/proxy.rs Outdated Show resolved Hide resolved
proxy/src/proxy.rs Outdated Show resolved Hide resolved
@conradludgate conradludgate enabled auto-merge (squash) July 31, 2023 10:47
@github-actions
Copy link

1240 tests run: 1188 passed, 0 failed, 52 skipped (full report)


@conradludgate conradludgate requested a review from skyzh July 31, 2023 12:04
@conradludgate conradludgate merged commit eb78603 into main Jul 31, 2023
@conradludgate conradludgate deleted the proxy/div-by-zero branch July 31, 2023 13:30
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