athenad: fix memory leak by closing Response objects (#34101)

* fix memory leak by closing Response

* use with
pull/34146/head
Dean Lee 5 months ago committed by GitHub
parent 685dc5a80c
commit 43807746ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      system/athena/athenad.py
  2. 2
      system/athena/tests/test_athenad.py

@ -258,13 +258,13 @@ def upload_handler(end_event: threading.Event) -> None:
sz = -1 sz = -1
cloudlog.event("athena.upload_handler.upload_start", fn=fn, sz=sz, network_type=network_type, metered=metered, retry_count=item.retry_count) 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): with _do_upload(item, partial(cb, sm, item, tid, end_event)) as response:
cloudlog.event("athena.upload_handler.retry", status_code=response.status_code, fn=fn, sz=sz, network_type=network_type, metered=metered) if response.status_code not in (200, 201, 401, 403, 412):
retry_upload(tid, end_event) cloudlog.event("athena.upload_handler.retry", status_code=response.status_code, fn=fn, sz=sz, network_type=network_type, metered=metered)
else: retry_upload(tid, end_event)
cloudlog.event("athena.upload_handler.success", fn=fn, sz=sz, network_type=network_type, metered=metered) else:
cloudlog.event("athena.upload_handler.success", fn=fn, sz=sz, network_type=network_type, metered=metered)
UploadQueueCache.cache(upload_queue) UploadQueueCache.cache(upload_queue)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.SSLError): except (requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.SSLError):

@ -240,7 +240,7 @@ class TestAthenadMethods:
@with_upload_handler @with_upload_handler
def test_upload_handler_retry(self, mocker, host, status, retry): def test_upload_handler_retry(self, mocker, host, status, retry):
mock_put = mocker.patch('requests.put') mock_put = mocker.patch('requests.put')
mock_put.return_value.status_code = status mock_put.return_value.__enter__.return_value.status_code = status
fn = self._create_file('qlog.zst') fn = self._create_file('qlog.zst')
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True)

Loading…
Cancel
Save