Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP sockets not getting released when disposing SubscriberSocket #1102

Open
SenseYang opened this issue Aug 28, 2024 · 0 comments
Open

TCP sockets not getting released when disposing SubscriberSocket #1102

SenseYang opened this issue Aug 28, 2024 · 0 comments

Comments

@SenseYang
Copy link

SenseYang commented Aug 28, 2024

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant