I have an application that is using NetMQ for pushing some data out to consumer processes. On some miraculous occasions, this application crashes. It is set up as a Windows service that automatically restarts after these crashes. On service start, we bind with the following code:
private static void InitializePublisher(string _queueAddress)
{
ctx = NetMQContext.Create();
netmqPublisher = ctx.CreatePushSocket();
netmqPublisher.Bind(_queueAddress);
netmqPublisher.Options.SendHighWatermark = 50;
netmqPublisher.Options.ReceivevHighWatermark = 50;
}
When the service stops through expected behaviour, we unbind and dispose the connection correctly. However, we have seen a few occasions where the service crashes and on restart it is unable to bind to that same address, since the crashed service is not letting go of its binding. Here is the exception we are seeing:
NetMQ.NetMQException ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at NetMQ.zmq.TcpListener.SetAddress(String addr)
--- End of inner exception stack trace ---
at NetMQ.zmq.TcpListener.SetAddress(String addr)
at NetMQ.zmq.SocketBase.Bind(String addr)
at NetMQ.zmq.ZMQ.Bind(SocketBase s, String addr)
at DataAccessManager.InitializePublisher(String _queueAddress)
Assuming we have control of the machine and know that the address should be available for use, is there a way to kill any open bindings on a given address so that we can bind to it?