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

Hang when sending an empty frame from REQ to REP

Open ikirill opened this issue 4 years ago • 1 comments

Describe the bug Sending an empty frame from REQ to REP hangs, while sending an empty string does not.

Reproducing

const zmq = require("zeromq");

(async () => {
    let back = new zmq.Reply();
    await back.bind("inproc://back");
    for await (let msg of back) {
        console.log({msg: msg.toString("utf8")});
        await back.send([msg]);
    }
})();

// (async () => {
//     let back = new zmq.Router();
//     await back.bind("inproc://back");
//     for await (let [who, dummy, msg] of back) {
//         console.log({who,dummy,msg});
//         await back.send([who, [], msg]);
//     }
// })();

(async () => {
    let socket = new zmq.Request();
    socket.connect("inproc://back");
    // FIXME
    // let msg = []; // hangs
    let msg = ""; // doesn’t hang
    for (let q = 0; ; q++) {
        await socket.send(msg);
        [msg] = await socket.receive();
        console.log(q);
    }
})();

If possible, provide a list of commands or a code sample that reproduces the bug that you are observing. Otherwise please describe as much as possible in which circumstances the bug can be observed.

Expected behavior It should be possible to send an empty frame, as I tested this in C++ with cppzmq. The documentation of zeromq is also quite clear that empty frames are a convention, and the sockets shouldn't even be inspecting what I'm sending through them, as I understand it.

Tested on

  • OS: Linux newton 5.13.4-200.fc34.x86_64 #1 SMP Tue Jul 20 20:27:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • ZeroMQ.js version: [email protected]

ikirill avatar Nov 14 '21 21:11 ikirill

Oh wait, I get it. [] is not an empty frame, it's interpreted as an array of frames, that has no frames in it, and I should have used [[]]. Should still probably be an error of some sort since in the C api it's impossible to call zmq_send with no message parts (each call is a single part).

ikirill avatar Nov 15 '21 09:11 ikirill