File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -186,12 +186,20 @@ gameManager.subscriber.on("connect", () => handleRedisConnection(gameManager.sub
186186gameManager . subscriber . on ( "reconnecting" , ( ) => handleRedisReconnection ( "sub" ) ) ;
187187gameManager . subscriber . on ( "error" , ( err ) => handleRedisError ( "sub" , err ) ) ;
188188
189- // Establish connections
190- gameManager . publisher . connect ( ) ;
191- gameManager . subscriber . connect ( ) ;
189+ // Initialize connections and subscription with proper sequencing
190+ async function initRedis ( ) {
191+ try {
192+ await gameManager . publisher . connect ( ) ;
193+ await gameManager . subscriber . connect ( ) ;
194+ // Subscribe only after connections are established
195+ gameManager . subscribe ( `${ process . env . INTERACTIVE_KEY } _RACE` ) ;
196+ } catch ( err ) {
197+ console . error ( "[Redis] Initialization error:" , err ) ;
198+ }
199+ }
192200
193- // Subscribe to race channel
194- gameManager . subscribe ( ` ${ process . env . INTERACTIVE_KEY } _RACE` ) ;
201+ // Kick off initialization (top-level)
202+ initRedis ( ) ;
195203
196204// Periodically prune stale SSE connections
197205setInterval ( ( ) => {
You can’t perform that action at this time.
0 commit comments