nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.28k stars 7.59k forks source link

Calling listen on microservice or startAllMicroServices doesn't not throw a catchable error when port is in use #6060

Closed iangregsondev closed 3 years ago

iangregsondev commented 3 years ago

Bug Report

Current behavior

Very simple to reproduce.

Some kind to start listening

  const microservice = app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${configService.gRPCListeningPort}`,
      package: [MAIN_NET_DATA_SERVICE_PACKAGE_NAME, STN_DATA_SERVICE_PACKAGE_NAME],
      protoPath: [
        path.join(__dirname, "grpc/main-net-services/proto/main-net-data-service.proto"),
        path.join(__dirname, "grpc/stn-services/proto/stn-data-service.proto"),
      ],
    },
  })

  //await app.startAllMicroservicesAsync()
  microservice.listen(() => {
    console.log("I am listening!")
  })

If the port is in use, an error is output into the console (see below) BUT it doesn't throw a catchable error in the application. Is this supposed to be like this?

I mean I have a microservice that appears to be working but in fact the port is in use but I can't seem to try / catch or anything to be able to log this ?

or even if the nestjs failed to start would be ok.

[Nest] 56069   - 01/01/2021, 10:26:41   [NestMicroservice] Nest microservice successfully started +104ms
E0101 10:26:41.353448000 4479000064 server_chttp2.cc:40]               {"created":"@1609493201.353423000","description":"No address added out of total 1 resolved","file":"../deps/grpc/src/core/ext/transport/chttp2/server/chttp2_server.cc","file_line":394,"referenced_errors":[{"created":"@1609493201.353422000","description":"Failed to add port to server","file":"../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc","file_line":404,"referenced_errors":[{"created":"@1609493201.353414000","description":"Failed to listen to port","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":72,"grpc_status":14,"os_error":"address already in use"}]}]}
[2021-01-01T10:26:41.419] [INFO] Main::Bootstrap - gRPC ready and listening on port 3010
[Nest] 56069   - 01/01/2021, 10:26:41   [RoutesResolver] MainNetController {}: +135ms
[Nest] 56069   - 01/01/2021, 10:26:41   [RoutesResolver] StnController {}: +0ms
I am listening!
[Nest] 56069   - 01/01/2021, 10:26:41   [NestApplication] Nest application successfully started +3ms

In a standard http app (using express) then it throws an errors and fails - which is good as this can be restarted right ?

Or am I missing something ?

Environment


Nest version: 7.4.4.

For Tooling issues:
- Node version: 14  
- Platform:  Mac big sur

kamilmysliwiec commented 3 years ago

We're tracking this here https://github.com/nestjs/nest/issues/2777