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 e99fab9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 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 Down

0 comments on commit e99fab9

Please sign in to comment.