Skip to content

Commit b1777dd

Browse files
committed
fix: handle too busy reconnection
1 parent 35223ce commit b1777dd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/y-socket-io/client.js

+2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ export class SocketIOProvider extends Observable {
351351
* @readonly
352352
*/
353353
onSocketDisconnection = (event) => {
354+
if (event === 'io server disconnect') this.socket.connect()
355+
354356
this.emit('connection-close', [event, this])
355357
this.synced = false
356358
AwarenessProtocol.removeAwarenessStates(

src/y-socket-io/y-socket-io.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ export class YSocketIO {
211211
const namespace = this.getNamespaceString(socket.nsp)
212212
if (toobusy()) {
213213
logSocketIO(`warning server too busy, rejecting connection: ${namespace}`)
214-
throw new Error('server too busy, please try again latter')
214+
// wait a bit to prevent client reconnect too fast
215+
await promise.wait(100)
216+
socket.send('server too busy, please try again latter')
217+
socket.disconnect(true)
218+
return
215219
}
216220
if (!socket.user) throw new Error('user does not exist in socket')
217221

0 commit comments

Comments
 (0)