Connection / Type Error in a hyprid App with NATS
See original GitHub issueI’m submitting a…
[ x] Bug report
Current behavior
I start a hypride service with NATS in a docker env. If this has to connect to a url that is not localhost, an error message will appear. If I start this service either as a non-hybrid service or under localhost, then it connects and there is no error message.
The error message is:
TypeError: “port” option should be a number or string: null at lookupAndConnect (net.js:1048:13)
at Socket.connect (net.js:1025:5)
at Object.connect (net.js:117:35)
at Client.createConnection (/server/node_modules/nats/lib/nats.js:808:23)
at new Client (/server/node_modules/nats/lib/nats.js:183:10)
at Object.exports.connect (/server/node_modules/nats/lib/nats.js:209:12)
at ServerNats.createNatsClient (/server/node_modules/@nestjs/microservices/server/server-nats.js :38:28)
at ServerNats.listen (/server/node_modules/@nestjs/microservices/server/server-nats.js:16:32)
at NestMicroservice.listen (/server/node_modules/@nestjs/microservices/nest-microservice.js:75:21)
at Promise (/server/node_modules/@nestjs/core/nest-application.js:193:32)
at new Promise (<anonymous>) at listenToPromise (/server/node_modules/@nestjs/core/nest-application.js:192:16)
at Array.map (<anonymous>) at NestApplication.startAllMicroservices (/server/node_modules/@nestjs/core/nest-application.js:117:40)
at resolve (/server/node_modules/@nestjs/core/nest-application.js:121:44) at new Promise (<anonymous>)
Expected behavior
Start a hypride service with NATS and without Errors
Minimal reproduction of the problem with instructions
import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/common/enums/transport.enum';
import { AppModule } from './app.module';
import config from './config/config';
const NATS_HOST = config.NATS_HOST;
const NATS_PORT = config.NATS_PORT;
const API_PORT = config.API_PORT;
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const microService = app.connectMicroservice({
transport: Transport.NATS,
options: {
url: `nats://${NATS_HOST}:${NATS_PORT}`,
},
});
await app.startAllMicroservicesAsync();
app.enableCors();
await app.listen(API_PORT);
}
bootstrap();
export default {
NATS_PORT: process.env.NATS_PORT || 4222, /* 4222 */
NATS_HOST: process.env.NATS_HOST || 'localhost', /*dev-nats*/
};
Environment
Nest version: 6.0.1 and 5.6
For Tooling issues:
- Node version: 8.15.0
- Platform: docker alpine
Others: More detailed explanation:
- If I use this on my local machine and connect to locahost: 4222, then i get connection without an error.
- if i connect another microservice ( a non hyprid) to the URL then i can connect to the NATS Service as normal.
The error occurs only in the constellation with the hyprid app and a non localhost address.
EDIT: Minimal repository: https://github.com/tolgas-adventures-in-wonderland/nest-js-hyprid-nats-bug-report
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Well, I just cloned your repository in my shell environment and it seems to work correctly. I changed
localhost
to random string and got no error - it works fine.In order to achieve the similar exception as yours, I had to explicitly pass
undefined
as host (which is an expected behavior). Are you sure that you don’t have any issues with your process vars?This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.