Skip to content

NetMQ.FaultException: Cannot close an uninitialised Msg. #930

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

Closed
valeriob opened this issue Aug 26, 2020 · 5 comments
Closed

NetMQ.FaultException: Cannot close an uninitialised Msg. #930

valeriob opened this issue Aug 26, 2020 · 5 comments

Comments

@valeriob
Copy link
Contributor

Hi,
this exception is raised every day at the same hour.
This is the stacktrace :

at NetMQ.Msg.Close() in //src/NetMQ/Msg.cs:line 458
at NetMQ.Core.Transports.StreamEngine.ProcessRoutingIdMsg(Msg& msg) in /
/src/NetMQ/Core/Transports/StreamEngine.cs:line 1142
at NetMQ.Core.Transports.V1Decoder.PushMsg(ProcessMsgDelegate sink) in //src/NetMQ/Core/Transports/V1Decoder.cs:line 175
at NetMQ.Core.Transports.StreamEngine.ProcessInput() in /
/src/NetMQ/Core/Transports/StreamEngine.cs:line 983
at NetMQ.Core.Transports.StreamEngine.FeedAction(Action action, SocketError socketError, Int32 bytesTransferred) in //src/NetMQ/Core/Transports/StreamEngine.cs:line 333
at NetMQ.Core.Utils.Proactor.Loop() in /
/src/NetMQ/Core/Utils/Proactor.cs:line 119
at System.Threading.ThreadHelper.ThreadStart_Context(Object state) in //src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs:line 50
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /
/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs:line 172
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in //src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /
/src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs:line 200
at System.Threading.ThreadHelper.ThreadStart() in /_/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs:line 100

I checked out the code at that version, and in StreamEngine.cs:line 1142 there is not a call to the Msg.Close() method.
The closest one are :

image

In case it's the first one, i have a bug somewhere, in case it's the second one, i have some doubts about the code.
This code should deterministically always raise the exception :

if (m_subscriptionRequired)
{
   Msg subscription = new Msg();
   subscription.Close();
   subscription.InitPool(1);
   subscription.Put((byte)1);
            
    m_session.PushMsg(ref subscription);
}

because after new Msg(), MsgType = MsgType.Uninitialised;
Given that m_subscriptionRequired is set to true in a branch of code where it says // check if it is an unversioned protocol (and i do not have any, since i only talk to my code deployed with the same version of netmq) is it possibile that some spurious data is causing the problem ?

Environment

NetMQ Version:    4.0.1.4
Operating System: Windows 10
.NET Version:     netcore 3.1

Expected behaviour

The process not to crash.

Actual behaviour

The process crashes constantly every day at the same time.

Steps to reproduce the behaviour

I'm still digging, can you give me some advice on how to track down the problem ?

Thanks
Valerio

@mnmr
Copy link
Contributor

mnmr commented Sep 6, 2020

I have just been through the same analysis and arrived at exactly the same conclusion: calling Close() on a new Msg will always result in a FaultException. The call to Close would only make sense for an existing/shared msg, rather than one having just been created.

This issue has only recently become a problem for us, and seems to only affect our public API server. I suspect it may be related to connections coming and going, as nothing else sticks out as being different from our other services. Perhaps the issue is triggered by messages arriving at a PUB/XPUB socket for which no subscription exists? We are using the ManualPublisher option (true) for XPUB sockets to authenticate subscribers.

Our call stack from the error is similar (but not identical) to the one reported above:

   at NetMQ.Msg.Close()
   at NetMQ.Core.Transports.StreamEngine.ProcessRoutingIdMsg(Msg& msg)
   at NetMQ.Core.Transports.V1Decoder.PushMsg(ProcessMsgDelegate sink)
   at NetMQ.Core.Transports.StreamEngine.ProcessInput()
   at NetMQ.Core.Transports.StreamEngine.Activate()
   at NetMQ.Core.Transports.StreamEngine.HandleHandshake(Action action, SocketError socketError, Int32 bytesTransferred)
   at NetMQ.Core.Transports.StreamEngine.FeedAction(Action action, SocketError socketError, Int32 bytesTransferred)
   at NetMQ.Core.Utils.Proactor.Loop()

@somdoron
Copy link
Member

somdoron commented Sep 7, 2020

@valeriob you are correct, line 1137 is a mistake and should be removed.
Do you want to make a pull request?

I think I would be able to reproduce this with an XPUB and Stream sockets.

@somdoron
Copy link
Member

somdoron commented Sep 7, 2020

is it possibile that some spurious data is causing the problem ?

Might be, some other application might try and connect to the port.

@valeriob
Copy link
Contributor Author

valeriob commented Sep 7, 2020

Sure, there you go #933
I'm asking because the service is running on a client's network, i know nothing about it and the service crashes consistently every day at 6.56am :D It's not happening in any other environment where the sw it's installed.
Looking at the code, i think i understood that the exception came from a code path handling a client not explicitly saying what protocol version it's using, since i'm the only one deploying both the client and the server, and they both use the same version of this library, i deducted that it's some other service making a connection to that socket.
Is it possible ?

@valeriob
Copy link
Contributor Author

Hi,
it looks likek that #933 fixed the issue :D

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

3 participants