@@ -14,6 +14,7 @@ import { User } from './user.js'
1414import { createModuleLogger } from 'lib0/logging'
1515import toobusy from 'toobusy-js'
1616import { promiseWithResolvers } from './utils.js'
17+ import { ClientClosedError } from 'redis'
1718
1819const logSocketIO = createModuleLogger ( '@y/socket-io/server' )
1920const 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
2223const WORKER_DISABLED = env . getConf ( 'y-worker-disabled' ) === 'true'
2324const DEFAULT_CLEAR_TIMEOUT = number . parseInt ( env . getConf ( 'y-socket-io-default-clear-timeout' ) || '30000' )
2425const 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
2628process . 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