-
Notifications
You must be signed in to change notification settings - Fork 38
feat(socket): use round robin for endpoints when the connection fails #92
Conversation
src/wire/Socket.ts
Outdated
@@ -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]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/wire/Socket.ts
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use modulo?
There was a problem hiding this comment.
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]
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.