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.

NATS microservice and client not reconnecting

See original GitHub issue

Bug Report

Current behavior

If a microservice app or client can’t connect to NATS server, or disconnects after connected, it throws an error but never tries to reconnect.

Input Code

const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.NATS,
    options:   {
      url:   'nats://localhost:4222',
      maxReconnectAttempts: -1,
    },
  });

Expected behavior

It should reconnect according to the connect options which sets maxReconnectAttempts and reconnectTimeWait.

Further things

  • The app never starts if there is no connection, instead it should retry until connected and then continue to start
  • If connection is lost after initially connected, ClientProxy.send() throws an error on first call, but then does not throw an error anymore. It shows an log in console “NatsError: Connection closed” but does not throw an error.
  • I dont see any hooks for logging. E.g. when the connection is lost I want to log an error and when the connection is back I want to log that, too. -> EDIT: Hooks are there but not accessible, see #6692

Environment


Nest version: 8.0.0-alpha.3
 
For Tooling issues:
- Node version: 15.6.0
- Platform:  macOS Big Sur


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilmysliwieccommented, Mar 19, 2021

Thanks @ceoro9! Let’s track this here https://github.com/nestjs/nest/pull/6696

1reaction
MickLcommented, Mar 18, 2021

Thanks for all your afforts!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection / Type Error in a hyprid App with NATS · Issue #1765
I start a hypride service with NATS in a docker env. If this has to connect to a url that is not localhost,...
Read more >
Automatic Reconnections - NATS Docs
Upon re-connection the client library will automatically re-establish all the subscriptions, there is nothing for the application programmer to do.
Read more >
Building a microservices architecture with NATS - Medium
Instead of connecting microservices in a point to point manner, NATS uses a hub-and-spoke topology where all the microservices are connected ...
Read more >
NATS Messaging - ThinkMicroservices.com
NATS clients connect and communicate with NATS servers. ... When you add a messaging dependency to your microservice architecture it is ...
Read more >
IP Security For Broadcasters: Part 10 - NATS Advanced ...
... control between apps and microservices and NATS messaging helps keep ... virtualization in mind from the outset, not as an afterthought.
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