Skip to content

Commit

Permalink
Merge pull request #17733 from mpoindexter/feature/fix-race-in-inspect
Browse files Browse the repository at this point in the history
Fix race condition
  • Loading branch information
andresriancho committed Mar 28, 2019
2 parents 556aacf + a9e2f67 commit f5adc9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
5 changes: 3 additions & 2 deletions w3af/core/controllers/threads/tests/test_threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ def sleep(sleep_time, **kwargs):
# Let the worker get the task
time.sleep(0.3)

func_name, func_args = worker_pool._pool[0].worker.get_real_func_name_args()
# Got it?
self.assertFalse(worker_pool._pool[0].worker.is_idle())
self.assertEqual(worker_pool._pool[0].worker.get_real_func_name(), 'sleep')
self.assertEqual(worker_pool._pool[0].worker.args, args)
self.assertEqual(func_name, 'sleep')
self.assertEqual(func_args, args)
self.assertEqual(worker_pool._pool[0].worker.kwargs, kwds)
self.assertGreater(worker_pool._pool[0].worker.job, 1)

Expand Down
38 changes: 22 additions & 16 deletions w3af/core/controllers/threads/threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,38 +203,44 @@ def __init__(self):
def is_idle(self):
return self.func is None

def get_real_func_name(self):
def get_real_func_name_args(self):
"""
Because of various levels of abstraction the function name is not always in
self.func.__name__, this method "unwraps" the abstractions and shows us
something easier to digest.
:return: The function name
"""
if self.func is None:
return None

if self.func is mapstar:
self.func = self.args[0][0]
self.args = self.args[0][1:]
# self.func/self.args could change over the execution of this method, so take
# a copy here.
current_func = self.func
current_args = self.args

if current_func is mapstar:
current_func = current_args[0][0]
current_args = current_args[0][1:]

if self.func is apply_with_return_error:
self.func = self.args[0][0]
self.args = self.args[0][1:]
if current_func is apply_with_return_error:
current_func = current_args[0][0]
current_args = current_args[0][1:]

if isinstance(self.func, return_args):
return self.func.func_orig.__name__
if isinstance(current_func, return_args):
return current_func.func_orig.__name__

if isinstance(self.func, one_to_many):
return self.func.func_orig.__name__
if isinstance(current_func, one_to_many):
return current_func.func_orig.__name__

if current_func is None:
return None

return self.func.__name__
return current_func.__name__, current_args

def get_state(self):
func_name = self.get_real_func_name()
func_name, func_args = self.get_real_func_name_args()

return {'func_name': func_name,
'args': self.args,
'args': func_args,
'kwargs': self.kwargs,
'start_time': self.start_time,
'idle': self.is_idle(),
Expand Down

0 comments on commit f5adc9e

Please sign in to comment.