From 07983e3563a0dbc9bf81fafee77cfc40b15b2486 Mon Sep 17 00:00:00 2001 From: wanghui Date: Fri, 21 Apr 2017 19:30:54 +0800 Subject: [PATCH] Fix CurlAsyncHTTPClient cause memory leak with `force_instance=True` The CurlAsyncHTTPClient will cause memory leak when set `force_instance=True`, because the `self._multi` and `self._force_timeout_callback` hold some methods that belong the instance of `CurlAsyncHTTPClient`, it will cause circular reference. --- tornado/curl_httpclient.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index eef4a17a6..554710ee4 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -74,6 +74,12 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): self._multi.close() super(CurlAsyncHTTPClient, self).close() + # Set below properties to None to reduce the reference count of current + # instance, because those properties hold some methods of current + # instance that will case circular reference. + self._force_timeout_callback = None + self._multi = None + def fetch_impl(self, request, callback): self._requests.append((request, callback)) self._process_queue() -- 2.47.2