question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection / Type Error in a hyprid App with NATS

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Mar 19, 2019

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?

0reactions
lock[bot]commented, Sep 23, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nats client connection error with web sockets - Stack Overflow
I am getting problem while connecting the nats.io with web socket ? "failed to reload", how we can connect with web sockets?
Read more >
Hybrid application - FAQ - A progressive Node.js framework
A hybrid application is one that both listens for HTTP requests, as well as makes use of connected microservices. The INestApplication instance can...
Read more >
Azure Relay Hybrid Connections protocol - Microsoft Learn
This article describes the client-side interactions with the Hybrid Connections relay for connecting clients in listener and sender roles.
Read more >
Investigating NATS Issues - DataMiner Docs
This error occurs when either there is a problem with the streaming section of the NATS config file ( C:\Skyline DataMiner\NATS\nats-streaming-server\nats- ...
Read more >
NATS Messaging - ThinkMicroservices.com
NATS clients connect and communicate with NATS servers. Currently, there are over thirty language-specific clients supported, including Java ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found