zeromq.node icon indicating copy to clipboard operation
zeromq.node copied to clipboard

Timing out a req/rep socket

Open nathasm opened this issue 11 years ago • 14 comments

It looks as though sndtimeo and rcvtimeo socket options are not supported. Is this correct? Or if it does, is there an example of how to set these options properly? What I have tried below doesn't seem to work.

var req = zmq.socket('req');
req.setsockopt(zmq.RCVTIMEO, 1000);
req.setsockopt(zmq.SNDTIMEO, 1000);
var sock = req.connect(endpoint);
sock.send(message);
sock.on('message', ...);
sock.on('error', ...);
sock.on('timeout', ...);

If the endpoint isn't up, I wait indefinitely.

nathasm avatar May 21 '13 14:05 nathasm

Also trying to find a solution to this issue... perhaps something similar to what was suggested for the python lib https://github.com/zeromq/pyzmq/issues/132

stowns avatar Aug 28 '13 23:08 stowns

That is not how the options are called, so it is evident that it will not work. The options are called ZMQ_RCVTIMEO and ZMQ_SNDTIMEO.

kkoopa avatar Aug 29 '13 08:08 kkoopa

I also tried the ZMQ_SNDTIMEO and ZMQ_RCVTIMEO options, I also set the ZMQ_LINGER, but to no avail.

nathasm avatar Aug 29 '13 17:08 nathasm

the options may be working at the zmq binding level but from what I can see the _flush method in the lib will only emit 'error' messages if there is an exception raised.

stowns avatar Aug 29 '13 17:08 stowns

It is supposed to emit an error on timeout. Problem seems to be that zmq_send and other operations should be blocking and have this behavior unless specified otherwise with a flag. For some reasone they seem not to block in zeromq.node, even though the flag is not set. I wonder if it could be the poller that is confusing it, because it works with libzmq.

kkoopa avatar Aug 29 '13 21:08 kkoopa

Sorry to ask, but is there any workaround for this?

lindem avatar Feb 24 '14 15:02 lindem

Same problem here guys... there's a workaround?

andreyvital avatar Apr 15 '14 12:04 andreyvital

No workaraound that I know of. Node.js does not like blocking operations, so everything in zeromq.node is non-blocking. These operations will always return instantly, putting messages on the queue for actual sending whenever possible. If there was some way of deleting queued messages, it might be possible to start a timeout and cancel it upon success and let it run and delete the message and raise an error on timeout.

kkoopa avatar Apr 15 '14 13:04 kkoopa

So per say, the only work around so far is to create a timeout on our side, and close the previous connection once the timeout happens, right?

I have implemented this simple timeout on waterfront - which i use to interface with zmq https://github.com/nowhereapp/waterfront/blob/master/lib/connect.js#L90-L118

definitely feels like zeromq should be doing the job, not node.js

:v:

hems avatar Jun 30 '14 00:06 hems

Any progress on this concern?

yamsellem avatar Feb 03 '15 17:02 yamsellem

@yamsellem my solution isn't perfect, but it will retry to execute req again... have a look.

hems avatar Feb 03 '15 23:02 hems

What was your solution? The link doesnt work

GMolini avatar Feb 13 '16 16:02 GMolini

@gumlym sorry man, it's been 1 year now. already dropped zeromq and waterfront. my solution now is totally based on redis and i couldn't be more happy.

hems avatar Feb 18 '16 19:02 hems

Ok never mind. I am using a workaround that just sets a a timeout whenever i send a message with nodejs (with the req socket), then if i havent received anything i just reset the socket (by closing it and opening it again), so that even if the message is produced after the timeout zeromq discards that message.

GMolini avatar Feb 18 '16 19:02 GMolini