Skip to content

Improve library thread-safety #256

@JamesWrigley

Description

@JamesWrigley

This library is a pretty thin wrapper around ZMQ and as such exposes most of its semantics, including its lack of threadsafety around sockets. What with Julia 1.12 coming up I think we should consider adding a threadsafe API for Socket.

I also noticed a case of ZMQ.jl being thread-unsafe in close(::Context):

ZMQ.jl/src/context.jl

Lines 74 to 82 in b4f30ae

function Base.close(ctx::Context)
if isopen(ctx) # don't close twice!
for w in getfield(ctx, :sockets)
s = w.value
if s isa Socket && isopen(s)
s.linger = 0 # allow socket to shut down immediately
close(s)
end
end

The function will first set the linger time of all sockets to 0 and close them, and then terminate the context. This is not threadsafe because the sockets may be running on a separate thread (e.g. the IJulia heartbeat thread).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions