From: wanghui Date: Fri, 21 Apr 2017 11:30:54 +0000 (+0800) Subject: Fix CurlAsyncHTTPClient cause memory leak with `force_instance=True` X-Git-Tag: v5.0.0~91^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07983e3563a0dbc9bf81fafee77cfc40b15b2486;p=thirdparty%2Ftornado.git 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. --- 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()