]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix CurlAsyncHTTPClient cause memory leak with `force_instance=True` 2022/head
authorwanghui <wh_linux@126.com>
Fri, 21 Apr 2017 11:30:54 +0000 (19:30 +0800)
committerwanghui <wh_linux@126.com>
Fri, 21 Apr 2017 11:30:54 +0000 (19:30 +0800)
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

index eef4a17a6b4a7e6e30c2db0ab5b1f44c2791ebea..554710ee4dd56b090c0cdb7b09bc36432fcb8898 100644 (file)
@@ -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()