Skip to content

Pr/check destination null #1093

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tmatthey
Copy link

Remove Debug.Assert(ok);, just return value of m_commandPipe.TryRead. I'm not certain if caller of Mailbox.TryRead may check if command.Destination to be not zero when processing the command, i.e., reading a command with CommandType.Done sent by ZObject.SendDone(), which has no destination.

@tmatthey
Copy link
Author

Is there a any chance that any can review and merge my PR? And is there a plan to release a new patch version including this PR? For now we running our application with a debug version including the changes of this PR and we have not seen any exceptions so far. Thanks in advance.

@drewnoakes
Copy link
Member

I'm interested to know why you had to defend against a null command in those places.

Also bumping xUnit has created some new warnings. Could you fix those up please, so we have a clean build? Thanks.

@tmatthey
Copy link
Author

@drewnoakes, you are right, it was not where I got the actual exception. I fixed all the warnings and put all the task awaiting into a separate class and resolves all your findings.

Process terminated. Assertion failed.
   at NetMQ.Core.Mailbox.TryRecv(Int32 timeout, Command& command)
   at NetMQ.Core.SocketBase.ProcessCommands(Int32 timeout, Boolean throttle, CancellationToken cancellationToken)
   at NetMQ.Core.SocketBase.GetSocketOptionX(ZmqSocketOption option)
   at NetMQ.NetMQSocket.GetSocketOptionX[T](ZmqSocketOption option)
   at NetMQ.NetMQSocket.get_HasIn()

@tmatthey
Copy link
Author

@drewnoakes did got any chance to take a look? With the last revert it is just removal of assert and oppgrade of System.ServiceModel.Primitives 4.10.3. Is there any chance to get en new patch release includeing this PR? Thanks in advance.

@tmatthey tmatthey force-pushed the pr/check-destination-null branch from dc0a9db to 7ecaa5f Compare June 4, 2024 16:40
@tmatthey
Copy link
Author

Any chance any could have a look again at this PR? I totally aware that this is an open-source on benevolent base, but I would really appreciate a new patch version.

@tmatthey tmatthey force-pushed the pr/check-destination-null branch from 7ecaa5f to fb96e78 Compare June 23, 2024 21:31
@tmatthey
Copy link
Author

I did a reset and force push to regroup the my changes and make hopefully clear: one for the trey-catch, one for grade of NuGet of the lib code, and one for upgrading NuGet's and fixing unit tests.

@follesoe
Copy link

follesoe commented Aug 4, 2024

Thanks for your efforts on this @tmatthey - I am making a local NetMq build based on your branch while waiting for this to get reviewed.

@tmatthey
Copy link
Author

tmatthey commented Aug 5, 2024

@follesoe Would be great if you could test too. I'm currently testing this branch in our environment with a local debug build, just to pickup any further asserts.

@tmatthey
Copy link
Author

I haven't seen any exceptions with a local debug build since my last commit 3 weeks ago.

@follesoe
Copy link

Me neither

@tmatthey tmatthey mentioned this pull request Dec 19, 2024
Comment on lines -235 to +234
// Get a command.
var ok = m_commandPipe.TryRead(out command);
Debug.Assert(ok);
return ok;
// We've got the signal. Now we can switch into active state if we can read.
m_active = m_commandPipe.TryRead(out command);
return m_active;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why this is needed? The previous code was expecting this to always return true. Is there a race? Why is this a safe change?

Comment on lines -1264 to 1265
Assumes.NotNull(command.Destination);
command.Destination.ProcessCommand(command);
command.Destination?.ProcessCommand(command);
found = m_mailbox.TryRecv(0, out command);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, why is this safe?

Comment on lines -183 to -193
// Try to prefetch a value.
if (!CheckRead())
try
{
// Try to prefetch a value.
if (!CheckRead())
{
value = default(T);
return false;
}

// There was at least one value prefetched.
// Return it to the caller.
value = m_queue.Pop();
return true;
}
catch
{
value = default(T);
return false;
}

// There was at least one value prefetched.
// Return it to the caller.
value = m_queue.Pop();
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding try/catch can hurt performance. Catching all exceptions raises eyebrows. While this is defensive, I'd like to understand what the actual issue is in order to fix it. Is there a test we could write that reproduces this behaviour, for example?

@follesoe
Copy link

I will revert to latest official NetMQ build and see if I can reproduce it. I ran into this issue numerous times on our Xamarin application, but switching to the fork from @tmatthey resolved many of the runtime issues.

I know many of the problems I experienced was due to how the .NET process was suspended and resumed, where the .NET Sockets where rehydrated and in the incorrect state because the underlying Socket's in iOS/Android had been freed.

If this was relevant for these particular changes I can't remember. Also, behavior might have changed on .NET 9 / MAUI which we are migrating to.

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

Successfully merging this pull request may close these issues.

3 participants