Giter Site home page Giter Site logo

Comments (5)

erickt avatar erickt commented on August 23, 2024

This is the normal ZMQ behavior, unless I'm missing something.

ZMQ supports two modes for shutting down the context. The first and default is that zmq_ctx_destroy will block until all the sockets are shut down across all of the threads. This is so ZMQ can guarantee all the messages have hit the underlying OS sockets. However this mechanism can cause a deadlock, because a ZMQ_REQ could be stuck waiting for a reply that may never happen. To avoid this scenario, you can set the socket option ZMQ_LINGER on the socket, as in socket.set_linger(100). This will give that ZMQ socket 100ms to finish it's IO before ZMQ will kill the OS socket and destroy the context.

I'm going to close this issue, but please feel free to reopen if I misinterpreted your problem.

from rust-zmq.

emberian avatar emberian commented on August 23, 2024

I can't reopen, but I think it should. I know this is how zmq works, but I think the wrapper is potentially incorrect. If you create sockets, and if their destructors don't get called before the context's destructor does, there will be an accidental hang.

from rust-zmq.

emberian avatar emberian commented on August 23, 2024

Note that it's not anything the user can control, it's the order the compiler decides to call constructors in. I imagine it'd do it in reverse creation order, but it needs to be verified.

from rust-zmq.

erickt avatar erickt commented on August 23, 2024

I get what you are saying, but is there any way to express this destructor dependency between contexts and sockets? Someone could always write:

fn bad() -> zmq::Socket {
  Let ctx = zmq::Context::new().unwrap();
  ctx.socket(zmq::ZMQ_REQ)
}

I don't think we can prevent that at compile time. Especially as we want to support moving sockets between threads.

The only other option I can think of is to just remove the destructors and potentially leak sockets/contexts. I'm not crazy about that idea though.

from rust-zmq.

emberian avatar emberian commented on August 23, 2024

Hrm, tricky. Don't think there's a nice way to do this "properly" :\

from rust-zmq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.