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

fix: connection robustness and flaky tests #5515

Merged
merged 98 commits into from
Dec 5, 2024
Merged

Conversation

ganchoradkov
Copy link
Member

@ganchoradkov ganchoradkov commented Nov 22, 2024

Description

Reworked several parts of the client to address general stability issues and to increase robustness of the socket connections

  • Implemented multi attempt connection logic in the relayer
  • Implemented graceful handling of disconnects mid publish
  • Reworked subscriber to attempt initial sub and let heartbeat retry to subscribe until success or reaching a timeout
  • Reworked publisher to attempt initial publish and let heartbeat retry to publish until success or reaching a timeout
  • Fixed several flaky tests that failed in bad network conditions with many disconnects
  • Improved error logging

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Draft PR (breaking/non-breaking change which needs more work for having a proper functionality [Mark this PR as ready to review only when completely ready])
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

canary - 2.17.2-canary-rcnt-3
deployment - https://react-dapp-v2-git-chore-connection-test-reown-com.vercel.app/

Checklist

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Additional Information (Optional)

Please include any additional information that may be useful for the reviewer.

@arein arein added the accepted label Nov 22, 2024
@ganchoradkov ganchoradkov marked this pull request as ready for review December 2, 2024 15:30
@ganchoradkov ganchoradkov changed the title fix: single connection attempt at a time fix: connection robustness and flaky tests Dec 2, 2024
Copy link
Contributor

@Cali93 Cali93 left a comment

Choose a reason for hiding this comment

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

LGTM, left comments mainly around readability.

}
};
this.relayer.events.on(RELAYER_EVENTS.publish, onPublish);
const initialPublish = createExpiringPromise(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not directly related to this PR but createExpiringPromise could use Promise.race to be simplified and avoid potential race conditions.
This approach eliminates the need for manual clearTimeout calls because once the Promise settles, the other Promise in the race is ignored, and the timer will be garbage collected.

export function createExpiringPromise<T>(
  promise: Promise<T>,
  expiry: number,
  expireErrorMessage?: string,
): Promise<T> {
  const timeoutPromise = new Promise<T>((_, reject) =>
    setTimeout(() => reject(new Error(expireErrorMessage)), expiry),
  );

  return Promise.race([promise, timeoutPromise]);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

will test it out duing tech debt week

packages/core/src/controllers/publisher.ts Show resolved Hide resolved
packages/core/src/controllers/publisher.ts Outdated Show resolved Hide resolved
packages/core/src/controllers/publisher.ts Outdated Show resolved Hide resolved
packages/core/src/controllers/publisher.ts Show resolved Hide resolved
packages/core/src/controllers/publisher.ts Show resolved Hide resolved
packages/core/src/controllers/subscriber.ts Outdated Show resolved Hide resolved
@ganchoradkov ganchoradkov merged commit 4596280 into v2.0 Dec 5, 2024
9 checks passed
@ganchoradkov ganchoradkov deleted the fix/single-connection branch December 5, 2024 10:06
@ganchoradkov ganchoradkov mentioned this pull request Dec 13, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants