NetMQ.NetMQException: Exception of type 'NetMQ.NetMQException' was thrown at NetMQ.Core.Ctx.CreateSocket(ZmqSocketType type)
Environment
NetMQ Version: 4.0.1.8
Operating System: Windows 10
.NET Version: 4.8.1
Expected behaviour
Actual behaviour
Throwing error: "NetMQ.NetMQException: Exception of type 'NetMQ.NetMQException' was thrown.\r\n at NetMQ.Core.Ctx.CreateSocket(ZmqSocketType type)\r\n at NetMQ.NetMQSocket..ctor(ZmqSocketType socketType, String connectionString, DefaultAction defaultAction)\r\n at NetMQ.Sockets.PairSocket.CreateSocketPair(PairSocket& socket1, PairSocket& socket2)\r\n at NetMQ.Core.Utils.StopSignaler..ctor()\r\n at NetMQ.NetMQPoller..ctor()\r\n at NetMQ.NetMQRuntime..ctor()\r\n at WMService.API.Services.Services.WMDispatcherService.<>c__DisplayClass4_0.<InvokeWindowmakerService>b__0()\r\n at System.Threading.Tasks.Task.InnerInvoke()\r\n at System.Threading.Tasks.Task.Execute()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at WMService.API.Services.Services.WMDispatcherService.<InvokeWindowmakerService>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at WMService.API.Services.Services.WindowmakerInterfaceService.<InvokeCalculate>d__5.MoveNext()"
Steps to reproduce the behaviour
- SendReceiveMessage always called when new API request comes.
- Error occurs after much successful responses.
public async Task
//await Task.Delay(1);
await Task.Factory.StartNew(() => {
var netMQRuntime = new NetMQRuntime();
netMQRuntime.Run(RunClient(messageString, responseMessage)); netMQRuntime.Dispose();
});
return responseMessage.message;
}
async Task RunClient(string messageString, ResponseMessage responseMessage)
{
using (var client = new DealerSocket())
{
bool more = false;
try
{
string address = "tcp://127.0.0.1";
string bindingAddress = $"{address}:{tcpPort}";
client.Connect(bindingAddress);
client.SendFrame(messageString);
(responseMessage.message, more) = await client.ReceiveFrameStringAsync();
}
catch (Exception ex)
{
responseMessage.message = ex.ToString();
}
finally
{
}
}
}
Can you print the number of iterations to calculate the number of sockets created? Furthermore, can you print the NetMQException ErrorCode?
I have witnessed the same behavior, in which Dispose does not seem to correctly finish cleaning up the socket. After some time, I reach the socket creation limit and get this exception:
Exception occurred: Exception of type 'NetMQ.NetMQException' was thrown. with error code: TooManyOpenSockets
Stack trace: at NetMQ.Core.Ctx.CreateSocket(ZmqSocketType type)
Related: https://github.com/zeromq/netmq/issues/1040