)]}'
{"swiftclient/client.py":[{"author":{"_account_id":15343,"name":"Tim Burke","email":"tburke@nvidia.com","username":"tburke"},"change_message_id":"46452410ee36d2e13f2d05b44783fd821e9cffe9","unresolved":false,"context_lines":[{"line_number":438,"context_line":"        if timeout:"},{"line_number":439,"context_line":"            self.requests_args[\u0027timeout\u0027] \u003d timeout"},{"line_number":440,"context_line":""},{"line_number":441,"context_line":"    def __del__(self):"},{"line_number":442,"context_line":"        \"\"\"Cleanup resources on delete\"\"\""},{"line_number":443,"context_line":"        if self.request_session:"},{"line_number":444,"context_line":"            # The session we create must be closed to free up open connections"}],"source_content_type":"text/x-python","patch_set":1,"id":"7faddb67_b74e4494","line":441,"range":{"start_line":441,"start_character":8,"end_line":441,"end_character":15},"updated":"2019-08-07 22:35:57.000000000","message":"I have one reservation about using __del__ -- IIRC, we won\u0027t have much control over when the cleanup happens, right? It\u0027s just kinda \"whenever the garbage collector gets around to it\" and in the mean time, the socket\u0027s still going to leak.\n\nHow do you feel about cleaning up the connection as soon as we\u0027re done with it? Something like\n\ndiff --git a/swiftclient/client.py b/swiftclient/client.py\nindex 4be2e2d..e3d110c 100644\n--- a/swiftclient/client.py\n+++ b/swiftclient/client.py\n@@ -1266,6 +1266,8 @@ def head_object(url, token, container, name, http_conn\u003dNone,\n     conn.request(method, path, \u0027\u0027, headers)\n     resp \u003d conn.getresponse()\n     body \u003d resp.read()\n+    if not http_conn:\n+        conn.close()\n     http_log((\u0027%s%s\u0027 % (url.replace(parsed.path, \u0027\u0027), path), method,),\n              {\u0027headers\u0027: headers}, resp, body)\n     if resp.status \u003c 200 or resp.status \u003e\u003d 300:\n\nOf course, it\u0027ll be a larger change -- it affects every top-level function :-/ -- but it has the benefit of releasing resources immediately.","commit_id":"4022084913f10db9752a55b16ec8075131c8ab4c"},{"author":{"_account_id":14985,"name":"Alex Schultz","email":"aschultz@next-development.com","username":"mwhahaha"},"change_message_id":"399290a52b0196dc0cb9c0fbca2d87e0605bb2bf","unresolved":false,"context_lines":[{"line_number":438,"context_line":"        if timeout:"},{"line_number":439,"context_line":"            self.requests_args[\u0027timeout\u0027] \u003d timeout"},{"line_number":440,"context_line":""},{"line_number":441,"context_line":"    def __del__(self):"},{"line_number":442,"context_line":"        \"\"\"Cleanup resources on delete\"\"\""},{"line_number":443,"context_line":"        if self.request_session:"},{"line_number":444,"context_line":"            # The session we create must be closed to free up open connections"}],"source_content_type":"text/x-python","patch_set":1,"id":"7faddb67_628d2829","line":441,"range":{"start_line":441,"start_character":8,"end_line":441,"end_character":15},"in_reply_to":"7faddb67_b74e4494","updated":"2019-08-12 14:44:51.000000000","message":"So it\u0027s not really leaking until it\u0027s garbage collected because it would be available for reuse because of keepalive.  The issue here is is really that we never properly close the session.  You don\u0027t want to close the connection every request because you\u0027ll take a perf hit for more complex usage.","commit_id":"4022084913f10db9752a55b16ec8075131c8ab4c"},{"author":{"_account_id":597,"name":"Pete Zaitcev","email":"zaitcev@kotori.zaitcev.us","username":"zaitcev"},"change_message_id":"59a403f7cb32126548fa329a2734b74a0459ede7","unresolved":false,"context_lines":[{"line_number":444,"context_line":"            # The session we create must be closed to free up open connections"},{"line_number":445,"context_line":"            try:"},{"line_number":446,"context_line":"                self.request_session.close()"},{"line_number":447,"context_line":"            except Exception:"},{"line_number":448,"context_line":"                pass"},{"line_number":449,"context_line":"            finally:"},{"line_number":450,"context_line":"                self.request_session \u003d None"}],"source_content_type":"text/x-python","patch_set":1,"id":"3fa7e38b_2fd5a243","line":447,"updated":"2019-12-05 21:36:58.000000000","message":"What does this empty clause do?\n\nI meant to write a diatribe on the evils of \"except Exception\" here, let the hate flow freely. But if the body is empty, perhaps we can just avoid the issue altogether.","commit_id":"4022084913f10db9752a55b16ec8075131c8ab4c"},{"author":{"_account_id":14985,"name":"Alex Schultz","email":"aschultz@next-development.com","username":"mwhahaha"},"change_message_id":"3ca4069119c1c5675c797ac9440302942d11cfa9","unresolved":false,"context_lines":[{"line_number":444,"context_line":"            # The session we create must be closed to free up open connections"},{"line_number":445,"context_line":"            try:"},{"line_number":446,"context_line":"                self.request_session.close()"},{"line_number":447,"context_line":"            except Exception:"},{"line_number":448,"context_line":"                pass"},{"line_number":449,"context_line":"            finally:"},{"line_number":450,"context_line":"                self.request_session \u003d None"}],"source_content_type":"text/x-python","patch_set":1,"id":"3fa7e38b_cfe08ece","line":447,"in_reply_to":"3fa7e38b_2fd5a243","updated":"2019-12-05 21:55:28.000000000","message":"if it\u0027s already closed it throws an exception. This is to just drop the exception","commit_id":"4022084913f10db9752a55b16ec8075131c8ab4c"},{"author":{"_account_id":597,"name":"Pete Zaitcev","email":"zaitcev@kotori.zaitcev.us","username":"zaitcev"},"change_message_id":"07276916466c7d703b1b2e1bffc7b278fc5ce1c4","unresolved":false,"context_lines":[{"line_number":444,"context_line":"            # The session we create must be closed to free up open connections"},{"line_number":445,"context_line":"            try:"},{"line_number":446,"context_line":"                self.request_session.close()"},{"line_number":447,"context_line":"            except Exception:"},{"line_number":448,"context_line":"                pass"},{"line_number":449,"context_line":"            finally:"},{"line_number":450,"context_line":"                self.request_session \u003d None"}],"source_content_type":"text/x-python","patch_set":1,"id":"3fa7e38b_4108dcd6","line":447,"in_reply_to":"3fa7e38b_cfe08ece","updated":"2019-12-07 19:02:49.000000000","message":"No exception is thrown if an already-closed session is closed again. But even if it were, the specific exception should be caught and not every one.","commit_id":"4022084913f10db9752a55b16ec8075131c8ab4c"}]}
