Skip to content

Commit

Permalink
fix memory leak by closing Response
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Nov 24, 2024
1 parent 957d39a commit 45f799b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions system/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,16 @@ def upload_handler(end_event: threading.Event) -> None:
sz = -1

cloudlog.event("athena.upload_handler.upload_start", fn=fn, sz=sz, network_type=network_type, metered=metered, retry_count=item.retry_count)
response = _do_upload(item, partial(cb, sm, item, tid, end_event))

if response.status_code not in (200, 201, 401, 403, 412):
cloudlog.event("athena.upload_handler.retry", status_code=response.status_code, fn=fn, sz=sz, network_type=network_type, metered=metered)
retry_upload(tid, end_event)
else:
cloudlog.event("athena.upload_handler.success", fn=fn, sz=sz, network_type=network_type, metered=metered)
response = _do_upload(item, partial(cb, sm, item, tid, end_event))
try:
if response.status_code not in (200, 201, 401, 403, 412):
cloudlog.event("athena.upload_handler.retry", status_code=response.status_code, fn=fn, sz=sz, network_type=network_type, metered=metered)
retry_upload(tid, end_event)
else:
cloudlog.event("athena.upload_handler.success", fn=fn, sz=sz, network_type=network_type, metered=metered)
finally:
response.close()

UploadQueueCache.cache(upload_queue)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.SSLError):
Expand All @@ -276,7 +279,7 @@ def upload_handler(end_event: threading.Event) -> None:

except queue.Empty:
pass
except Exception:
except Exception as ex:
cloudlog.exception("athena.upload_handler.exception")


Expand Down

0 comments on commit 45f799b

Please sign in to comment.