cetra3 / tmq

Rust ZeroMQ bindings for Tokio
150 stars 28 forks source link

Timeout on receive not working #47

Open guygg2048 opened 3 days ago

guygg2048 commented 3 days ago

Hi, I'm trying to use a REQ socket to send a message, and then have a timeout on the response in order to handle cases where a response is not sent in time. When I try it the program hangs after the time passes.

Here is a sample code:

let send_sock = tmq::request(&tme::Context::new()).connect("ipc://test.ipc")?;
let message: tmq::Message = "Hello".into();
let rec_sock = send_sock.send(message.into()).await?;
let (multipart, send_sock) = tokio::time::timeout(Duration::from_secs(1), recv_sock.recv()).await??;
...

I also tried to implement the same logic using tokio::select! and the result was similar.

cetra3 commented 1 day ago

I think this might be a problem with cancel safety, ZeroMQ and those socket types. The Req and Rep sockets are in lock step. If you send a message, then the only thing you can do is receive a message, if you cancel receiving a message, I'm not sure what should happen to the state of that socket.

Does the same thing happen if you use another socket type?