Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1997)

Unified Diff: appengine/swarming/swarming_bot/bot_code/remote_client.py

Issue 2593863002: Fix evil retry loop on poll errors. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/swarming_bot/bot_code/remote_client.py
diff --git a/appengine/swarming/swarming_bot/bot_code/remote_client.py b/appengine/swarming/swarming_bot/bot_code/remote_client.py
index 9d8f2cc60460df971f23445d16feb906e76aaa33..92a0ca7b4f5cd6f307cf793d139ccdf9c3e5abdc 100644
--- a/appengine/swarming/swarming_bot/bot_code/remote_client.py
+++ b/appengine/swarming/swarming_bot/bot_code/remote_client.py
@@ -11,9 +11,10 @@ import urllib
from utils import net
-from remote_client_errors import InitializationError
from remote_client_errors import BotCodeError
+from remote_client_errors import InitializationError
from remote_client_errors import InternalError
+from remote_client_errors import PollError
# RemoteClient will attempt to refresh the authentication headers once they are
@@ -214,12 +215,15 @@ class RemoteClientNative(object):
"""Polls for new work or other commands; returns a (cmd, value) pair as
shown below.
- Note that if the returned dict does not have the correct
- values set, this method will raise an exception.
+ Raises:
+ PollError if can't contact the server after many attempts, the server
+ replies with an error or the returned dict does not have the correct
+ values set.
"""
resp = self._url_read_json('/swarming/api/v1/bot/poll', data=attributes)
- if not resp:
- return (None, None)
+ if not resp or resp.get('error'):
+ raise PollError(
+ resp.get('error') if resp else 'Failed to contact server')
cmd = resp['cmd']
if cmd == 'sleep':
@@ -232,7 +236,7 @@ class RemoteClientNative(object):
return (cmd, resp['version'])
if cmd == 'restart':
return (cmd, resp['message'])
- raise ValueError('Unexpected command: %s\n%s' % (cmd, resp))
+ raise PollError('Unexpected command: %s\n%s' % (cmd, resp))
def get_bot_code(self, new_zip_path, bot_version, bot_id):
"""Downloads code into the file specified by new_zip_fn (a string).

Powered by Google App Engine
This is Rietveld 408576698