Closed milan-zededa closed 1 year ago
@milan-zededa this is solid! I saw you wrote a test program here. With this program, it fails with the SIGSEGV on the existing code, and succeeds with your new code?
@milan-zededa this is solid! I saw you wrote a test program here. With this program, it fails with the SIGSEGV on the existing code, and succeeds with your new code?
Yes, correct. On the existing code it fails within few seconds. With patch it was running without issues for hours.
Is there any way to make this a regular go test? I see that it uses an actual interface, which obviously wouldn't work, but could we simulate it? As you showed, the issue is continuing to stream data to the ring buffer after it tries to close. Is that simulatable without terrible headache?
Is that simulatable without terrible headache?
Probably not an easy task. Injecting memory region from unit test is doable but faking content with valid packet data (or even just envelopes) seems like a tons of work (and headache). Plus there is the socket and operations around it that would be difficult to mock.
Probably not an easy task. Injecting memory region from unit test is doable but faking content with valid packet data (or even just envelopes) seems like a tons of work (and headache). Plus there is the socket and operations around it that would be difficult to mock.
Good point. If we could extract the processing from the socket and abstract a lot of it, then we could, but that is not surgery I want us to undertake now. Let's leave it then.
Converting to draft - found one more race condition (less probable).
@deitch @eriknordmark Added one more commit - see the commit description and the content. It turned out that there is another race condition hiding. I will keep my test now running for a very long time.
When it is ready for review, remove it from Draft
and comment please.
I approved it. When you are comfortable the testing is complete, comment here, and we can merge it in.
@deitch I tested it thoroughly and it looks good now.
Done. Might want to pull it into eve now
When handle is closed,
isOpen
is atomically set to 0 to stopReadPacketData
from reading more packets. However,processMmapPackets
may still continue in the background processing packets remaining in the buffer. Then, asClose
unmaps the memory containing the buffer,processMmapPackets
may find itself reading from invalid memory regions. The right solution is forClose
to wait for an ongoingReadPacketData
to finalize before unmapping the memory. This can be achieved using CAS instructions.PR addresses the issue reported here: https://github.com/packetcap/go-pcap/issues/41