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

MQ Server crashes on FaultException #1101

Open
WojakGra opened this issue Aug 26, 2024 · 3 comments
Open

MQ Server crashes on FaultException #1101

WojakGra opened this issue Aug 26, 2024 · 3 comments

Comments

@WojakGra
Copy link

Environment

NetMQ Version: 4.0.1.13
Operating System: Windows 10 Pro x64
.NET Version: 4.7.2

Explanation

I have tasks with a loop, where in this loop I use the function 'NetMQ_SendFrame', which sends information by converting object to JSON string. The server crashes with error down below

Code

Server

private void NetMQ_Start()
{
    mqserver = new PublisherSocket();
    mqserver.Bind("tcp://127.0.0.1:5555");

    poller = new NetMQPoller { mqserver };
    poller.RunAsync();
}
private void NetMQ_SendFrame(PLCController controller, string msg)
{
    try
    {
        mqserver.SendFrame(msg);
    }
    catch (NetMQ.FaultException e)
    {
        LogEvent($"{controller.ID} - {controller.Name}: NetMQ SendFrame Fault Error");
    }
    catch (Exception e)
    {
        LogEvent($"{controller.ID} - {controller.Name}: NetMQ SendFrame Error");
    }
}

Client

private void InitializeNetMQ()
{
    mqclient = new SubscriberSocket();
    mqclient.Connect("tcp://127.0.0.1:5555");
    mqclient.Subscribe("");
    mqclient.ReceiveReady += Subscriber_ReceiveReady;

    poller = new NetMQPoller { mqclient };
    poller.RunAsync();
}
private void Subscriber_ReceiveReady(object sender, NetMQSocketEventArgs e)
{
    string message = e.Socket.ReceiveFrameString();
    if (message != null || message != "")
    {
        UpdatePLCList(message);
    }
}

Model of message

public class TemplateSendPLCList
{
    public string MachineID {  get; set; }
    public string MachineName { get; set; }
    public string Type { get; set; }
    public string IP { get; set; }
    public bool IsRunning { get; set; }
    public string Status { get; set; }
    public DateTime MessageTime { get; set; }
    public object readData { get; set; }
    public object writeData { get; set; }
    public object resultData { get; set; }
}

Error

Unhandled exception: NetMQ.FaultException
   at NetMQ.Msg.Close()
   at NetMQ.Core.Transports.EncoderBase.Encode(NetMQ.Core.Transports.ByteArraySegment ByRef, Int32)
   at NetMQ.Core.Transports.StreamEngine.BeginSending()
   at NetMQ.Core.Transports.StreamEngine.Handle(Action, System.Net.Sockets.SocketError, Int32)
   at NetMQ.Core.Transports.StreamEngine.FeedAction(Action, System.Net.Sockets.SocketError, Int32)
   at NetMQ.Core.Transports.StreamEngine.ActivateOut()
   at NetMQ.Core.SessionBase.ReadActivated(NetMQ.Core.Pipe)
   at NetMQ.Core.Pipe.ProcessActivateRead()
   at NetMQ.Core.ZObject.ProcessCommand(NetMQ.Core.Command)
   at NetMQ.Core.IOThread.Ready()
   at NetMQ.Core.Utils.Proactor.Loop()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
@amosialek
Copy link

I'm Experiencing the same issue in old codebase after switching from ZeroMQ nuget to NetMQ. Issue happens from time to time. Is there option to catch these exceptions just to avoid crash?

@WojakGra
Copy link
Author

I tried to implement exceptions but decided to get diffrent approach. I made a class for queue that sends the message with timer inside in Task.

@WojakGra
Copy link
Author

In this way I got rid of the problem, where there was a possibility that two messages wanted to send at the same time and an error was shown

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

5 participants
@amosialek @WojakGra and others