dugsong / pypcap

Automatically exported from code.google.com/p/pypcap
Other
117 stars 45 forks source link

Thread safety problem in pcap_ex_next() #31

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use pypcap in a multi-threaded scenario, with each thread using a 
   separate pcap instance.
2. In each thread, read packets via pcap.next(), in parallel.

What is the expected output? What do you see instead?

Expected output is normal packet retrieval. Instead, one sees occasional
packet truncation (e.g., caplen 46, IP hlen indicating full 1500B). The
cause for this is the additional static pcap_pkthdr variable in pcap_ex_next
and the fact that the hdr variable in __next__ points to it, as races may
not reflect the right content at the time it is accessed.

I'm attaching a patch that fixes the problem for me. It removes the
static variable, thus restoring pcap's "caller owns value" semantics in 
this particular case.

What version of the product are you using? On what operating system?

SVN trunk, Linux 2.6.

Original issue reported on code.google.com by kreib...@gmail.com on 2 Feb 2011 at 9:26

Attachments: