Commit dbdca225 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Add MAX_RETRIES to deobfuscator.py

Prevernts spamming bot logs when java_deobfuscate.py is broken

Bug: 1075998
Change-Id: I0d56ffde20e58c065b6ff575673f656a4396f745
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2169764
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763467}
parent f0402dd0
......@@ -16,6 +16,7 @@ from pylib import constants
_MINIUMUM_TIMEOUT = 3.0
_PER_LINE_TIMEOUT = .002 # Should be able to process 500 lines per second.
_PROCESS_START_TIMEOUT = 10.0
_MAX_RESTARTS = 10 # Should be plenty unless tool is crashing on start-up.
class Deobfuscator(object):
......@@ -141,15 +142,24 @@ class DeobfuscatorPool(object):
self._pool = [Deobfuscator(mapping_path) for _ in xrange(pool_size)]
# Allow only one thread to select from the pool at a time.
self._lock = threading.Lock()
self._num_restarts = 0
def TransformLines(self, lines):
with self._lock:
assert self._pool, 'TransformLines() called on a closed DeobfuscatorPool.'
# De-obfuscation is broken.
if self._num_restarts == _MAX_RESTARTS:
return lines
# Restart any closed Deobfuscators.
for i, d in enumerate(self._pool):
if d.IsClosed():
logging.warning('deobfuscator: Restarting closed instance.')
self._pool[i] = Deobfuscator(self._mapping_path)
self._num_restarts += 1
if self._num_restarts == _MAX_RESTARTS:
logging.warning('deobfuscator: MAX_RESTARTS reached.')
selected = next((x for x in self._pool if x.IsReady()), self._pool[0])
# Rotate the order so that next caller will not choose the same one.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment