go-zeromq / zmq4

[WIP] Pure-Go implementation of ZeroMQ-4
BSD 3-Clause "New" or "Revised" License
344 stars 57 forks source link

Pull socket can not be properly closed, if no clients ever connected #117

Closed egorse closed 2 years ago

egorse commented 2 years ago

Sorry for bit wacky title but step into problem that next test is fails.

func TestPullSocket1(t *testing.T) {
    assert := asserts.New(t)

    // Create pull socket
    ctx, cancel := context.WithCancel(context.Background())
    pull := zmq4.NewPull(ctx)
    assert.NotNil(pull)
    err := pull.Listen("ipc://@TestPullSocket1")
    assert.NoError(err)

    // Cancel and close socket
    // This as well might be in time.AfterFunc with the same result!!!!
    cancel()
    err = pull.Close()
    assert.NoError(err)

    // Read out
    msg, err := pull.Recv()
    assert.Error(err)
    _ = msg

    // Final close
    err = pull.Close()
    _ = err
}

To me it looks like Close() should make qreader.sem.enable() as in this case qreader.addConn() is never called and qreader.read() stuck forever in q.sem.lock()

egorse commented 2 years ago

Sorry - seems already fixed in master

sbinet commented 2 years ago

I've tagged v0.14.0.

egorse commented 2 years ago

Thank you @sbinet! You've 100% correctly identified root cause - think this is pretty common for modules :)