[IMP] http: improve dumpstacks and remaining requests handling during tests (#18640)
This patch modifies Root#dispatch() in order to keep the httprequest url in the current thread's attribute and use if for dumpstacks and the phantomjs tests remaining requests handling. Also added a counter in order to avoid looping forever when trying to join unclosed http requests in phantomjs test suite after a phantomjs failure + added a log.warning in such a case so it's easier to troubleshoot runbot's ir.logging.
This commit is contained in:
@@ -1440,6 +1440,7 @@ class Root(object):
|
||||
httprequest = werkzeug.wrappers.Request(environ)
|
||||
httprequest.app = self
|
||||
httprequest.parameter_storage_class = werkzeug.datastructures.ImmutableOrderedMultiDict
|
||||
threading.current_thread().url = httprequest.url
|
||||
|
||||
explicit_session = self.setup_session(httprequest)
|
||||
self.setup_db(httprequest)
|
||||
|
||||
@@ -163,6 +163,8 @@ def application_unproxied(environ, start_response):
|
||||
del threading.current_thread().uid
|
||||
if hasattr(threading.current_thread(), 'dbname'):
|
||||
del threading.current_thread().dbname
|
||||
if hasattr(threading.current_thread(), 'url'):
|
||||
del threading.current_thread().url
|
||||
|
||||
with odoo.api.Environment.manage():
|
||||
# Try all handlers until one returns some result (i.e. not None).
|
||||
|
||||
@@ -393,11 +393,17 @@ class HttpCase(TransactionCase):
|
||||
t0 = int(time.time())
|
||||
for thread in threading.enumerate():
|
||||
if thread.name.startswith('odoo.service.http.request.'):
|
||||
thread.join_retry_count = 10
|
||||
while thread.isAlive():
|
||||
# Need a busyloop here as thread.join() masks signals
|
||||
# and would prevent the forced shutdown.
|
||||
thread.join(0.05)
|
||||
time.sleep(0.05)
|
||||
thread.join_retry_count -= 1
|
||||
if thread.join_retry_count < 0:
|
||||
_logger.warning("Stop waiting for thread %s handling request for url %s",
|
||||
thread.name, thread.url)
|
||||
break
|
||||
time.sleep(0.5)
|
||||
t1 = int(time.time())
|
||||
if t0 != t1:
|
||||
_logger.info('remaining requests')
|
||||
|
||||
+5
-3
@@ -1038,15 +1038,17 @@ def dumpstacks(sig=None, frame=None):
|
||||
# modified for python 2.5 compatibility
|
||||
threads_info = {th.ident: {'name': th.name,
|
||||
'uid': getattr(th, 'uid', 'n/a'),
|
||||
'dbname': getattr(th, 'dbname', 'n/a')}
|
||||
'dbname': getattr(th, 'dbname', 'n/a'),
|
||||
'url': getattr(th, 'url', 'n/a')}
|
||||
for th in threading.enumerate()}
|
||||
for threadId, stack in sys._current_frames().items():
|
||||
thread_info = threads_info.get(threadId, {})
|
||||
code.append("\n# Thread: %s (id:%s) (db:%s) (uid:%s)" %
|
||||
code.append("\n# Thread: %s (id:%s) (db:%s) (uid:%s) (url:%s)" %
|
||||
(thread_info.get('name', 'n/a'),
|
||||
threadId,
|
||||
thread_info.get('dbname', 'n/a'),
|
||||
thread_info.get('uid', 'n/a')))
|
||||
thread_info.get('uid', 'n/a'),
|
||||
thread_info.get('url', 'n/a')))
|
||||
for line in extract_stack(stack):
|
||||
code.append(line)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user