Open
Description
Environment
NetMQ Version: 4.0.1.12
Operating System: Windows 11
.NET Version: 6
Expected behaviour
I expect the TCP sockets to be released when disposing a Subscriber socket.
Actual behaviour
The process hangs after socket.Dispose()
is called.
Steps to reproduce the behaviour
In my code, the subscriber socket will be used this way:
var socket = new SubscriberSocket();
var connectionAddress = $"tcp://{host.EnsureIsNotNullOrEmpty()}:{port}";
socket.Connect(_connectionAddress);
socket.SubscribeToAnyTopic();
var receiveLogThread = new Thread(() => ReceiveLog(host, port));
receiveLogThread.IsBackground = true;
receiveLogThread.Start();
ReceiveLog is implemented:
private void ReceiveLog(string host, int port)
{
while (!_socket.IsDisposed)
{
string messageReceived = string.Empty;
try
{
messageReceived = _socket.ReceiveFrameString();
}
catch (Exception e)
{
_logger.LogError(_loggingContext, $"Receiving frame string failed with exception: {e.ToString()}.");
continue;
}
// processing message
}
}
And at disposal:
if (!_socket.IsDisposed)
{
socket.Dispose();
receiveLogThread.Join();
GC.SuppressFinalize(this);
}
Expect that the process can exit after Dispose() is called.
With logging in the code, I can confirm that it hangs after calling socket.Dispose().
Metadata
Metadata
Assignees
Labels
No labels