Skip to content

Commit ded3f1d

Browse files
committed
fix: suppress redis error
1 parent 04a4bf2 commit ded3f1d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { User } from './user.js'
1414
import { createModuleLogger } from 'lib0/logging'
1515
import toobusy from 'toobusy-js'
1616
import { promiseWithResolvers } from './utils.js'
17+
import { ClientClosedError } from 'redis'
1718

1819
const logSocketIO = createModuleLogger('@y/socket-io/server')
1920
const PERSIST_INTERVAL = number.parseInt(env.getConf('y-socket-io-server-persist-interval') || '3000')
@@ -22,6 +23,7 @@ const REVALIDATE_TIMEOUT = number.parseInt(env.getConf('y-socket-io-server-reval
2223
const WORKER_DISABLED = env.getConf('y-worker-disabled') === 'true'
2324
const DEFAULT_CLEAR_TIMEOUT = number.parseInt(env.getConf('y-socket-io-default-clear-timeout') || '30000')
2425
const WORKER_HEALTH_CHECK_INTERVAL = number.parseInt(env.getConf('y-socket-io-worker-health-check-interval') || '5000')
26+
const NEVER_REJECT_CONNECTION = env.getConf('y-socket-io-never-reject-connection') === 'true'
2527

2628
process.on('SIGINT', function () {
2729
// calling .shutdown allows your process to exit normally
@@ -232,7 +234,7 @@ export class YSocketIO {
232234
assert(this.client)
233235
assert(this.subscriber)
234236
const namespace = this.getNamespaceString(socket.nsp)
235-
if (toobusy()) {
237+
if (!NEVER_REJECT_CONNECTION && toobusy()) {
236238
logSocketIO(`warning server too busy, rejecting connection: ${namespace}`)
237239
// wait a bit to prevent client reconnect too fast
238240
await promise.wait(100)
@@ -392,6 +394,7 @@ export class YSocketIO {
392394
this.cleanupNamespace(ns, stream, DEFAULT_CLEAR_TIMEOUT)
393395
if (this.namespaceDocMap.has(ns)) this.debouncedPersist(ns, true)
394396
}
397+
logSocketIO(`disconnecting socket in ${ns}, ${nsp?.sockets.size || 0} remaining`)
395398
}
396399
})
397400
socket.onAnyOutgoing(async (ev) => {
@@ -562,7 +565,10 @@ export class YSocketIO {
562565

563566
await this.client.trimRoomStream(namespace, 'index')
564567
} catch (e) {
565-
console.error(e)
568+
// suppress redis client closed error
569+
if (!(e instanceof ClientClosedError)) {
570+
console.error(e)
571+
}
566572
}
567573
},
568574
timeoutInterval

0 commit comments

Comments
 (0)