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.

stan.js doesn't try to reconnect

See original GitHub issue

I have the following code, running on node-nats-streaming@0.3.2, which successfully connects to server setup using docker using nats-streaming:0.18-alpine image:

const STAN = require('node-nats-streaming')

const { NATS_CONN_URL } = require('../config')

let url = NATS_CONN_URL
let sc = STAN.connect('mail-cluster', 'node-worker', {
  url,
})

// emitted whenever there's an error. if you don't implement at least
// the error handler, your program will crash if an error is emitted.
sc.on('error', (err) => {
  console.log("[NATS] Error:", err)
})

// connect callback provides a reference to the connection as an argument
sc.on('connect', () => {
  console.log(`[NATS] connected`)
})
 
// emitted whenever the client disconnects from a server
sc.on('disconnect', () => {
  console.log('[NATS] disconnect')
})
 
// emitted whenever the client is attempting to reconnect
sc.on('reconnecting', () => {
  console.log('reconnecting')
})
 
// emitted whenever the client reconnects
// reconnect callback provides a reference to the connection as an argument
sc.on('reconnect', () => {
  console.log(`[NATS] reconnect`)
})
 
// emitted when the connection is closed - once a connection is closed
// the client has to create a new connection.
sc.on('close', function () {
  console.log('[NATS] close')
})
 
// emitted whenever the server returns a permission error for
// a publish/subscription for the current user. This sort of error
// means that the client cannot subscribe and/or publish/request
// on the specific subject
sc.on('permission_error', function (err) {
  console.error('[NATS] got a permissions error', err.message)
})

However, when there are network connectivity issues, there are no reconnect attempts, it just fails with the following output:

[NATS] connected
[NATS] close

Am I doing anything wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rabeeshcharlescommented, Sep 9, 2021

Great…Let me give a try…

0reactions
aricartcommented, Sep 9, 2021

Also - if you are starting work using stan.js, you should really stop and start looking at jetstream instead, which is supported directly by all our current javascript clients. https://github.com/nats-io/nats.deno/blob/main/jetstream.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rstan compile issues after updating to R 4.0.3 - Developers
Is caused by rstan trying to connect to github to check your model against the new version of the compiler. The easiest fix...
Read more >
Do not buy the LG 27UL850 monitor for its USB-C hub feature
Hi @stanislas - I just received the LG 27UK850 and Tried to connect via USB-C with the mfg USB-C cable. What I found...
Read more >
Node js - Socket.io-client is not connecting to socket.io server
I am trying to connect to a socket.
Read more >
JavaScript vs Stan | What are the differences? - StackShare
JavaScript and Stan are primarily classified as "Languages" and "Machine ... I'd suggest you stick to one language and trying developing everything using...
Read more >
Chromecast Not Working: 8 Simple Fixes | WhistleOut
To fix your Chromecast setup issues, you can try the following: ... Wait around 30 seconds to 1 minute before trying to connect...
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