Add a workaround for ConnectionResetErrors in task_log_view()

When running a task (e.g. importing other distribution data), the web
frontend polls to get task output every second. In the view handling
this request we check to see if the underlying Celery task is finished
by getting the AsyncResult and then calling result.ready().
Unfortunately that latter call seems to be failing some of the time in
the development Docker setup that I am using, throwing a
ConnectionResetError. Because the polling is regular it doesn't really
matter if this fails as there'll be another chance on the next poll, so
just allow the call to fail silently. (It pains me to put in workarounds
like this but at the moment I can't determine the real cause of the
issue, and this stops the stream of ultimately useless error report
emails that I'm getting as an admin of the development instance).

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-05-30 09:23:53 +12:00
parent ca56e1c664
commit 170259df39

View File

@ -1550,7 +1550,13 @@ def task_log_view(request, task_id):
origlen = len(datastr)
data = escape(datastr)
response = HttpResponse(data)
if result.ready():
try:
ready = result.ready()
except ConnectionResetError:
# FIXME this shouldn't be happening so often, but ultimately we don't care -
# the frontend is polling so it'll likely succeed in a subsequent request
ready = False
if ready:
response['Task-Done'] = '1'
updateobj = get_object_or_404(Update, task_id=task_id)
response['Task-Duration'] = utils.timesince2(updateobj.started, updateobj.finished)