Closed isnolan closed 2 years ago
Looks like an issue with your environment. Please, use our Discord for such issues. We are using GitHub to track bugs, feature requests, and potential improvements.
@micalevisk I couldn't think it was my environmental problem, so I tried more.
Build docker locally, the problem remains. In the next few steps, I will try to reproduce this problem with the local docker image
Using other ports, everything works normally. (eliminate environmental factors?)
Disable the code await app.startAllMicroservices()
, everything works normally. (seems to be here?)
Next, read the source code and try to reproduce the problem
Change the TCP_DEFAULT_PORT
3000 port number in node_modules/@nestjs/microservices/constants.js
to 3001, everything is back to normal. At this time, the service is still running on port 3000. It is found that ports 3000 and 3001 are occupied.
Explore the code TCP_DEFAULT_PORT
and find that it seems that the port number can be customized. Try to define the port number as 3001 in Transport.TCP
options. At this time, the service can operate normally on port 3000.
const app = await NestFactory.create(AppModule); app.connectMicroservice
({ transport: Transport.TCP, options: { retryAttempts: 5, retryDelay: 3000, port:3001 }, }); await app.startAllMicroservices(); await app.listen(3000);
Here, we find that under the local development and production modes, the two ports can be the same. I believe @nestjs does not intend to make them different. However, we have reason to believe that in the docker environment, there is indeed a possibility of port conflict. My knowledge can not explain how the docker environment will be different. Let's record it for now. I hope someone can explain this. I will avoid this problem by changing the port number for the time being. thank you.
Is there an existing issue for this?
Current behavior
I encountered the problem that 3000 ports were occupied in the project, and the local development environment was normal. In 'sample/03-microservices', switch the port number to 3000 and upload the code to k8s to minimize the recurrence of this problem.
`
Minimum reproduction code
https://github.com/yhostc/nestjs-03-microservices
Steps to reproduce
gitlab-ci
to build the code.Expected behavior
Successfully used 3000 port.
Package
Other package
No response
NestJS version
^9.0.1
Packages versions
Node.js version
16.16.0-alpine
In which operating systems have you tested?
Other
No response