Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto reconnect if writer failed to connect to NSQ #69

Open
fizerkhan opened this issue Apr 20, 2015 · 13 comments
Open

Auto reconnect if writer failed to connect to NSQ #69

fizerkhan opened this issue Apr 20, 2015 · 13 comments

Comments

@fizerkhan
Copy link

Once it is disconnected from NSQ(Manually kill the NSQ server), the 'closed' event has been triggered in the writer. Then start NSQ server, again. But writer failed to reconnect the server. It throws following error

2015-04-20T10:35:58.359Z - error: Error: No active Writer connection to send messages
    at Writer.publish (/Users/guest/myserver/node_modules/nsqjs/lib/writer.js:99:13) 

It will be great if you have auto reconnect in the Writer. Is there any other method to do it?

@mehdivk
Copy link

mehdivk commented Apr 21, 2015

Is there any update about this issue and do you accept a PR for this one? I think this feature would be handy.

@dudleycarr
Copy link
Owner

I think it's worth addressing since it's a common concern. I'll hopefully get to it soon.

@fizerkhan
Copy link
Author

Is there any update on this issue? In production, it becomes very critical. Application gets hanged and not responding to any requests. Even in development, writer gets closed if machine went to sleep.

@dudleycarr
Copy link
Owner

I'll work on a solution today. As a workaround, you can listen for the close event and then reconnect. It's not elegant but it will work. That's effectively what the implementation will be within the Reader.

@fizerkhan
Copy link
Author

Thanks @dudleycarr. Currently i just did worst workaround of process.exit and make supervisord start the node server again. I will try with reconnect and looking for your solution 👍

@fizerkhan
Copy link
Author

@dudleycarr is there any update on this issue?

@hilkeheremans
Copy link

Just to add, I also believe it would be a useful addition (to both Reader and Writer). I worked around it manually for now by wrapping the nsqjs library.

@oaleynik
Copy link

oaleynik commented Jun 1, 2016

As a workaround it is possible to use https://www.npmjs.com/package/retry to reconnect. It is easy to set listener for closed event and stop messages to be published while reconnecting. The tricky part is to buffer incoming messages during reconnection.

Any chance to have it landed soon? /cc: @dudleycarr

@thomasmodeneis
Copy link

I'm also facing same problems here:

[0] Writer closed
[0] events.js:154
[0]       throw er; // Unhandled 'error' event
[0]       ^
[0] 
[0] Error: read ECONNRESET
[0]     at exports._errnoException (util.js:856:11)
[0]     at TCP.onread (net.js:546:26)

@oaleynik this retry project is real nice, thanks for the tip. Only missing now is buffer the incoming messages as you just mentioned! 👍

@whtiehack
Copy link

@dudleycarr when resolve this issue?

@rsaphala
Copy link

bump

@rbudiharso
Copy link

rbudiharso commented Dec 20, 2022

Happens to me too

@xavierchow
Copy link
Contributor

There is a wrapper npm that provide auto-reconnection.
https://github.com/Wiredcraft/nsq-strategies#nsqd-connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants