pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.17k stars 166 forks source link

Problem with repeated requests when REP is unavailable #163

Closed olegkotsar closed 4 years ago

olegkotsar commented 4 years ago

Hello.

I think REQ/REP not working as intended. If the REP socket is unavailable, REQ sockets send requests, when the REP becomes available again, then it receives all the repeated requests that the REP sent, but should have received only one (without repeated).

This problem can be seen using these two examples: https://github.com/pebbe/zmq4/blob/master/examples/lpserver.go https://github.com/pebbe/zmq4/blob/master/examples/lpclient.go

I launch client:

#go run lpclient.go
I: connecting to server...
W: no response from server, retrying...
W: no response from server, retrying...
I: server replied OK (1)

After a few seconds, I start the server:

#go run lpserver.go
I: normal request ([1])
I: normal request ([1])
I: normal request ([1])
I: normal request ([2])

We can see that received three requests "I: normal request ([1])", instead of one.


A sequence of actions:

  1. In lpclient.go increase retries, example _REQUESTRETRIES = 10
  2. Run lpclient.go - go run lpclient.go
  3. Wait few second
  4. Run lpserver.go - go run lpclient.go

    My enviroment:

    #go version
    go version go1.14.2 linux/amd64
    #pkg-config --modversion libzmq
    4.3.1

    I tried lpclient and lpserver scripts on Perl, Python. It works as expected, without repetitions of messages.

Tell me, please, how can I fix this?

Kind regards, Oleg

pebbe commented 4 years ago

I don't see how this is a problem. It seems that this is how the ZeroMQ library works.

olegkotsar commented 4 years ago

Yes, you are right, it seems that this is normal behavior, to control the repetition of messages (and exclude them) I added a unique identifier for each message. This is described in The Guide - http://zguide.zeromq.org/page:all#Idempotent-Services