You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello community, i am developing a chat app with Nest.js and SocketIo and i want to run it in cluster mode and still have polling as transport,I know that for this i need to have an adapter and sticky sessions enabled.With the adapter i succeed(here is the code)
But i got stuck for sticky sessions here is mine main.ts
asyncfunctionbootstrap(){constlogger=newLogger();constapp=awaitNestFactory.create(AppModule);app.useGlobalPipes(newValidationPipe({transform: true}));app.enableCors({origin: '*',});constsocketIOAdapter=newSocketIOAdapter(app);app.useWebSocketAdapter(socketIOAdapter);constconfigService: ConfigService=app.get(ConfigService);constport: number=configService.get('port');constnodeEnv: string=configService.get('NODE_ENV');if(nodeEnv!==NODE_ENV.PRODUCTION){constconfig=newDocumentBuilder().setTitle('Chat application').setDescription('The corporative chat application written in Nest').setVersion('1.0').addBearerAuth({type: 'http',name: 'accessToken'}).build();constdocument=SwaggerModule.createDocument(app,config);SwaggerModule.setup('api/docs',app,document);}consthttpServer=app.getHttpServer();constio=newServer(httpServer);setupWorker(io);awaitapp.listen(port);logger.log(`Find docs on http://localhost:${port}/api/docs`,'NestApplication',);}construnningOnCluster: boolean=Object.values(NODE_ENV).filter((env)=>env!==NODE_ENV.LOCAL).findIndex((env)=>env===process.env.NODE_ENV)>-1;if(runningOnCluster){if(clusterInstance.isPrimary){consthttpServer=http.createServer();setupMaster(httpServer,{loadBalancingMethod: 'least-connection',});clusterInstance.setupPrimary({serialization: 'advanced',});constcpuCount=os.cpus().length;for(leti=0;i<cpuCount;i+=1){clusterInstance.fork();}clusterInstance.on('online',(worker)=>{Logger.log(`${worker.process.pid} is online`,'NestApplication::Cluster');});clusterInstance.on('exit',({ process })=>{Logger.log(`${process.pid} died`,'NestApplication::Cluster');});}else{bootstrap();}}else{bootstrap();}
getting the error:
Error: server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration
at WebSocketServer.completeUpgrade (C:\chat-backend\node_modules\ws\lib\websocket-server.js:363:13)
at WebSocketServer.handleUpgrade (C:\chat-backend\node_modules\ws\lib\websocket-server.js:339:10)
at callback (C:\chat-backend\node_modules\engine.io\build\server.js:564:21)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello community, i am developing a chat app with Nest.js and SocketIo and i want to run it in cluster mode and still have polling as transport,I know that for this i need to have an adapter and sticky sessions enabled.With the adapter i succeed(here is the code)
But i got stuck for sticky sessions here is mine main.ts
getting the error:
Error: server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration
at WebSocketServer.completeUpgrade (C:\chat-backend\node_modules\ws\lib\websocket-server.js:363:13)
at WebSocketServer.handleUpgrade (C:\chat-backend\node_modules\ws\lib\websocket-server.js:339:10)
at callback (C:\chat-backend\node_modules\engine.io\build\server.js:564:21)
Beta Was this translation helpful? Give feedback.
All reactions