Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

feat(socket): use round robin for endpoints when the connection fails #92

Merged
merged 2 commits into from
Jan 26, 2018

Conversation

EthanWaite
Copy link
Contributor

If the connection to interactive is dropped, connect to the next server served by /interactive/hosts (and cycle through them). Also expands the recoverable error codes to include CloudFlare errors, server restarts, etc.

@@ -13,7 +13,7 @@ import {
/**
* Close codes that are deemed to be recoverable by the reconnection policy
*/
export const recoverableCloseCodes = [1000, 1011];
export const recoverableCloseCodes = [1000, 1001, 1006, 1011, 1012];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please use an enum for those?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were normal ws closure codes, rather than codes specifically sent by tetrisd. But thinking about it, it probably makes more sense to rid of this altogether and just reconnect on any 1xxx error. Only issue there is that Edge serves 1005 for all closures, so that may have to be excluded for compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

It still makes sense to define an enum rather than throwing random numbers around.

@@ -369,6 +370,14 @@ export class InteractiveSocket extends EventEmitter {
this.socket.send(payload);
}

private getURL(): string {
const addresses = this.options.urls;
if (this.endpointIndex >= addresses.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use modulo?

Copy link
Contributor

Choose a reason for hiding this comment

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

eg. return addresses[endpointIndex % addresses.length]

@ProbablePrime ProbablePrime merged commit 264abaa into master Jan 26, 2018
@ProbablePrime ProbablePrime deleted the feature/roundrobin branch January 26, 2018 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants