mikolalysenko / mudb

Low latency state replication for the web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Auto-reconnect socket wrapper

hediyi opened this issue · comments

An opt-in wrapper handling auto-reconnection on abnormal closures for WebSocket socket types, for now having no aspirations to be generic. The wrapper should also buffer outbound messages until an attempt succeeds or abandoning.

new MuReconnectSocket(new MuWebSocket())

// above is equal to
new MuReconnectSocket(new MuWebSocket(), {
    maxAttempts: Infinity,  // max number of attempts before giving up
    delay: 1000,            // ms to wait before first reconnect attempt, also the coefficient of exponential backoff
    timeout: 2000,          // ms to wait before closing a pending connection
})
  1. It's more consistent if we make the websocket just another property of the spec: ie
new MuReconnectSocket({
   socket: new MuWebSocket(),
})
  1. The sockets should also accept some max buffer size, maybe measured in bytes. If a reconnect socket buffers more than the allotted amount of data, close it.
  2. There also should be a symmetric socket server interface. To prevent session id collisions the underlying reconnect socket API will probably need to put a prefix on the session id that it sends to the server. Also the server will need to buffer messages on its side in the event of a socket disconnection.