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

When using a timeout when calling erlzmq:recv () can lose a message #61

Open
dmelnik opened this issue Jul 19, 2013 · 2 comments
Open

Comments

@dmelnik
Copy link

dmelnik commented Jul 19, 2013

If the messages in the queue at the time of the call is not, but it it appears after the timeout, it is lost
This occurs because the timeout is implemented using receive ... after, and the message that it is obtained when the timeout has passed, there is no one to accept the message, and it remains in the queue process

(a similar situation with erlzmq:send (), but it returns {error, eagain}, even though the message was sent)

test case:

zmq_recv_error() ->
{ok, C} = erlzmq:context(),
{ok, BS} = erlzmq:socket(C, [pull]),
ok = erlzmq:setsockopt(BS, rcvtimeo, 1000),
ok = erlzmq:bind(BS, "tcp://127.0.0.1:5555"),
spawn_link(
fun() ->
{ok, C2} = erlzmq:context(),
{ok, CS2} = erlzmq:socket(C2, [push]),
ok = erlzmq:connect(CS2, "tcp://127.0.0.1:5555"),
timer:sleep(1500),
ok = erlzmq:send(CS2, <<"some data">>),
ok = erlzmq:close(CS2),
ok = erlzmq:term(C2)
end),
case erlzmq:recv(BS) of
{error, eagain} ->
io:format("error:pn", [eagain]),
case erlzmq:recv(BS) of
{error, eagain} ->
io:format("error:pn", [eagain]),
io:format("~nERROR!n");
{ok, Data} ->
io:format("data:pn", [Data]),
io:format("nOKn")
end;
{ok, Data} ->
io:format("data:pn", [Data]),
io:format("OK
n")
end.

@yrashk
Copy link
Member

yrashk commented Aug 21, 2013

cc @okeuday: have you experienced anything like this?

@okeuday
Copy link
Contributor

okeuday commented Aug 21, 2013

i think this is a problem when not using active receives... so a problem with passive receives and all sends. The timeout being at:
https://github.com/zeromq/erlzmq2/blob/master/src/erlzmq.erl#L189
https://github.com/zeromq/erlzmq2/blob/master/src/erlzmq.erl#L254
I think this behaviour is by-design, it must timeout, so there isn't a better option I am aware of. If this behaviour is a concern, the timeout can always be set to be blocking (a timeout of infinity). When this problem does occur, the process will still get the message later, but it will remain unhandled and possibly ignored.

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

No branches or pull requests

3 participants