-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Race condition when instantiating Packet subclasses in multiple threads #1966
Comments
Could you try your fix with the following script #642 and report the before/after values for comparison?
|
Ran it my laptop with several other applications running. So not the perfect benchmarking environment.
|
Wouldn’t it be possible to edit Let's not start to add Locks within Scapy :/ that'll kill some perf at larger scales / faster rates. You could also be responsible for the Rlock when you builds your packets, rather than within Scapy :-) If the one-shot dict doesn't work, it's a wontfix for me |
Any news about this issue? |
I cannot reproduce the issue on different Linux setups =/ @gpotter2 any hint to fix this without locks ? |
That's easy to fix. The issue happens only on the first instanciation (first call of Will provide a patch |
I finally managed to reproduce the issue by assigning 2000 to |
Brief description
When
Packet
subclasses are used in multiple threads, there is a potential for a race condition.Environment
How to reproduce
This issue will only be triggered with a very specific timing, and is hard to reproduce. But in theory it may present itself any time you have multiple threads concurrently instantiating any of the
Packet
subclasses. To increase the chances, this script can be used:Running this code in a loop will likely trigger the exception.
Actual result
The exception raised looks like the following. It shows that certain field names don't exist in
self.fieldtype
.Possible fixes/workarounds
This issue seems to be related to the field caching mechanism used in the
Packet
class.Using a lock makes the issue disappear. The following is just a proof of concept. It needs more testing and review to ensure it won't cause other issues. Perhaps the locking can be made more granular.
Workarounds I've been able to use to avoid this issue:
Instantiating the subclasses once in the main thread, before other threads are started. That will populate the cache.
Disabling the cache for each subclass used by threads. e.g.:
The text was updated successfully, but these errors were encountered: