zeromq / clrzmq4

ZeroMQ C# namespace (.NET and mono, Windows, Linux and MacOSX, x86 and amd64)
GNU Lesser General Public License v3.0
242 stars 112 forks source link

receiveframe times out with EGAIN exactly the 255th time #32

Closed madhulika closed 9 years ago

madhulika commented 9 years ago

Hi,

I don't know if this is an issue with my usage or a real issue that needs fixing. Either way, please see if you can help

I am using zmq router-dealer configuration. The server is written in python and runs on linux. My dealer client is written in c# with clrzmq4 and runs on a windows machine. It sends messages and waits from the response

    public Boolean sendMessage(Dictionary<String, String> msgDict)
    {
        ZError err;
        String errStr;
        var reqFrame = new ZFrame(JsonConvert.SerializeObject(msgDict));
        retval = socket.Send(reqFrame, out err);
        if (err != null)
        {
            errStr = String.Format("Error while sending command {3} {0} {1}", err.Text, err.Number, err.Name);
            return false;
        }

        err = null;

        respFrame = socket.ReceiveFrame(out err);

        if (err != null)
        {
            errStr = String.Format("Error while receiving response data {0} {1} {2} {3}", err.Text, err.Number, err.Name, num_messages);
            return false;
        }
        return true;
   }

set the sendTimeout and receiveTimeout on the socket to 2 min each. When I keep calling sendMessage, exactly at the 255th time, receiveFrame timesout . On the server I see the message being processed and response being sent like everytime. And after this point, my send also timesout with the same error "EAGAIN" Resource temporarily unavailable. There are the things I tried

  1. Data with different lengths from 2 KB to 20 MB
  2. set the sendhighwatermark and receivehighwatermark to different values: 10, 1000, 10000
  3. Tried polling on the socket instead of ReceiveFrame
  4. Tried making the sockets completely blocking. In each of the above cases the failure occured at exactly the 255th time. In case of blocking sockets, it got blocked at the 255th time too. I also tried a dealer client from another linux machine and it had no issues 255th time or even later.
metadings commented 9 years ago

Don't exactly know... but I don't have a problem sending and receiving thousands of messages :)

madhulika commented 9 years ago

I turned off curvezmq auth and I can send thousands of messages fine. When I turn on the auth I get stuck at 255. Need to figure out why. Any pointers will be appreciated. Couldn't find any examples which used curvezmq auth to verify my usage.

metadings commented 9 years ago

Hehe, you're on the right way... the Curve25519 encryption is currently not really implemented (in clrzmq4; in the used libzmq IT IS), something like a ZAuthenticationBase and Curve25519Authentication, PlainAuthentication...

However: You can set the ZSocket.CurvePublicKey, CurveSecretKey and .CurveServerKey (which does set the CurveServer option indirectly). (If you have set them, you need to check them if they are set...)

public byte[] CurveServerKey {
    get { return GetOptionBytes(ZSocketOption.CURVE_SERVERKEY); }
    set { SetOption(ZSocketOption.CURVE_SERVERKEY, value); }
}

Now you need also a ZAP handler, like a ZActor and the like... I'm currently not really in-the-code, so... could YOU please fork this project to write an update? :+1:

madhulika commented 9 years ago

yes I am setting the keys, but when I try to access them I get an exception. But they seem to be getting used, because when I don't set them no messages go through as auth fails. when I set the keys, I can't access them but 255 messages go through :-)

metadings commented 9 years ago

ok well, that part with " you need to check them " was just a guess :-)

madhulika commented 9 years ago

From what I understand the Auth implementation is not planned in the near future, right!! That brings me to the next question, what is the future of this project. Will it be maintained and updated. You are the major contributor with just 2 commits from others. What plans do you have w.r.to this project.

metadings commented 9 years ago

I wrote this project and I'm maintaining it (I have set git remote add zeromq https://github.com/zeromq/clrzmq4 and always write git push zeromq master).

And yes, the future and plan to implement is... that you are going to fork the project, write an update and when it's good I'm going to push your update to clrzmq4 ;) I have just time for some minutes now and I'd like to see you tomorrow :)

madhulika commented 9 years ago

Thank you. Will follow your plan if I can't get curvezmq with zmq on windows. That seems to be the case anyway as netmq does not have it either.

metadings commented 9 years ago

Yeah, I see ZeroMQ making very many keys and it is fixing your nonces, so you may just encrypt/decrypt and sign/verify your ZFrames directly using (Tweet)NaCl, as I do try this in my tweetnacl.c and TweetNaCl.cs projects; I'm currently not using the C program; I bound my methods to libsodium.

madhulika commented 9 years ago

Have an update to share. We upgraded the server side on linux from pyzmq 14.6.0 to 14.7.0(which has zmq version 4.1.2) and this issue of failure at 255th time vanished.

With curve keys setup, I can send thousands of messages without failure. clrzmq4 does seem to support Curve25519 encryption. Good news for me.

metadings commented 9 years ago

:+1:

Well, please press on Fork on the top-right on github! You will have to

C:\Projects>git clone https://github.com/madhulika/clrzmq4
// don't know what git said ^^
C:\Projects>cd clrzmq4

// here you make your changes...

C:\Projects\clrzmq4>git add -A
C:\Projects\clrzmq4>git commit -m "Updating clrzmq4"
C:\Projects\clrzmq4>git push origin master

// here you make changes again...

Now you can send your changes now to github (git add ... git commit ... git push), and you will be able to send me your Pull Request !

metadings commented 9 years ago

You will have to BUILD the project now !

Using Windows in Visual Studio (Express) 2010+ open file ZeroMQ.vs.csproj, using ubuntu Linux (C 4.8.2) in MonoDevelop 5+ open file ZeroMQ.mono.csproj...

You should now have a fully qualified ZeroMQ project in your favorite IDE, being able to create new projects based on ZeroMQ/CLRZMQ4 and you also can make changes to the ZeroMQ/CLRZMQ4 project. (by doing git add -A & git commit -m "Updating ZeroMQ" & git push zeromq master)

Beware: You need to set the files in folders i386 and amd64 to Copy if newer (if you didn't just open the csproj).