Reputation: 80372
I'm wondering if you have any recommendations to track down a tricky problem that involves UDP multicast packets being handled by multiple threads.
Are there any debugging techniques in .NET that you can use to track down bugs in multithreaded environments that involve network UDP packets?
How do I get visibility in such an environment?
Upvotes: 1
Views: 304
Reputation: 134065
Without more information, I can't give specific recommendations. I'd start with the following.
The first thing I'd do is check to see if there are possible race conditions in the code that aggregates and reassembles the packets. Somehow, you're taking packets from multiple threads and combining them. Typically this is done in one of two ways: either the individual threads queue packets for processing by a dedicated thread (a multiple producer, single consumer design), or you use some kind of synchronization that allows the threads to share a buffer. That is, each thread adds its incoming packet to the combined packet.
The former is easier to control. You can use a concurrent queue (such as the .NET BlockingCollection
) and not worry about synchronization. If you're using a Queue<T>
with a lock, or if your individual threads are cooperating to combine the packets, you have to make sure that there aren't any holes in your synchronization.
Another possibility is that one or more of the incoming packets is corrupt in some way, or the reader isn't reading it correctly. You should log every incoming packet along with the thread number and the time it came in. When the problem crops up, you can check the log to see if the packets are in good shape. If they are, then the problem is almost certainly with your synchronization.
Absent more information about your specific application, I don't have any other recommendations.
Upvotes: 3