-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verify=False causing memory leak #5215
Comments
verify=False
causing memory leak
@AndTheDaysGoBy I've just tried using urllib3 as seen in the function below and the memory usage is stable, slightly more then using the requests package but regardless the memory is stable at about approximately 15.1mb for over 30 minutes. It's strange as it only happens when using verify=False on I've also added some additional memory usage stats using pympler to the original post. def check_status():
global running
url = "https://swapi.co/api/films/1/"
http = urllib3.PoolManager(key_file=None, cert_file=None, cert_reqs='CERT_NONE', ca_certs=None)
while running:
response = http.request('GET', url)
time.sleep(5) |
@tallona Seems your statistics imply something is repeatedly generating lists in the case of
The approach I'd take if I were you is to isolate further and further the issue. I.e., does the issue appear when using Edit:
|
@AndTheDaysGoBy Done a bit more testing using I've also taken your code example and run it locally, when using verify False I'm seeing a memory increase over time but using verify True the memory usage is stable. def check_status():
global running
url = "https://swapi.co/api/films/1/"
while running:
response = requests.request(method='GET', url=url, verify=False)
time.sleep(5) |
@tallona Meaning, you constantly see a memory diff? Or do you perform something like Since you state If that still is the issue, then try instantiating Line 84 in 2e0f38c
manually, i.e. the adapters.py HTTPAdapter object and sending via that. If that no longer fails then the issue would at least be something in the sessions.py. If the issue persists, then the issue is likely somewhere in adapters.py. |
The initial report was for Python 3.7.4 on Windows. You might be affected by the Windows-only bug https://bugs.python.org/issue37702 |
Can confirm this bug when using Affected environment: Winpython 64 3740/3741) Thanks to @tiran to pointing that out! |
Any solution, for this, I have the same problem. python: 3.7 |
OMG! I can confirm verify=False leaks memory so bad. The past 10 days has been hell for me trying to find the leak in my python app |
What's your platform, Python version, and requests version? |
Windows 10 |
You have to update to a newer version of 3.7 series. 3.7.4 has a memory leak that only affects Windows. |
As @tiran pointed out this does appear to be resolved in https://bugs.python.org/issue37702. We haven't seen new reports of this in almost a year, so I'm going to resolve. If you are still experiencing this on Python 3.7.5+, please open a new issue linking back to this one so we can track separately. Thanks! |
When I use
verify=False
inrequests.get
the memory usage creeps up over time until all memory is used up, if I removeverify=False
then the memory usage is stable at approximately about 14.2-14.9mb over time.I've changed the request to use
verify=True
and memory usage is stable at the expected usage I've seen as outlined above.When using the
requests.get
function I can see the memory usage slowly creeping up via task manager by watching the spawned process.I've watched this over a two hour period in both cases and when using
verify=False
the memory usage is at 1GB+ after two hours.I've recreated the issue using a free API that uses no auth, sample script attached.
What you expected
Memory usage to be stable enough during life time of script running.
What happened instead
Memory usage creeps up over time and will use up all server memory available eventually.
Sample Script
System Information
Pympler summary
Some additional information, I've used pympler to give some memory usage with verify set as both possibilities.
1 - Start of script - verify=False
==================================== | =========== | ============
<class 'str | 13937 | 1.59 MB
<class 'dict | 2014 | 1.09 MB
<class 'code | 4445 | 626.77 KB
<class 'type | 563 | 588.95 KB
<class 'set | 147 | 144.16 KB
<class 'tuple | 1574 | 107.02 KB
<class 'wrapper_descriptor | 1213 | 94.77 KB
<class 'weakref | 1093 | 85.39 KB
<class 'abc.ABCMeta | 84 | 83.24 KB
<class 'builtin_function_or_method | 1042 | 73.27 KB
<class 'method_descriptor | 945 | 66.45 KB
<class 'int | 1891 | 56.13 KB
<class 'list | 314 | 53.05 KB
<class 'getset_descriptor | 689 | 48.45 KB
<class 're.Pattern | 87 | 44.62 KB
2 - 4/5 minutes into run - verify=False
==================================== | =========== | ============
<class 'list | 61274 | 22.22 MB
<class 'str | 75877 | 5.81 MB
<class 'dict | 2434 | 1.17 MB
<class 'code | 4445 | 626.77 KB
<class 'type | 563 | 588.95 KB
<class 'int | 12663 | 350.91 KB
<class 'set | 167 | 148.53 KB
<class 'tuple | 1573 | 106.91 KB
<class 'wrapper_descriptor | 1213 | 94.77 KB
<class 'collections.OrderedDict | 104 | 92.80 KB
<class 'weakref | 1093 | 85.39 KB
<class 'abc.ABCMeta | 84 | 83.24 KB
<class 'builtin_function_or_method | 1042 | 73.27 KB
<class 'method_descriptor | 945 | 66.45 KB
<class 'bytes | 123 | 50.75 KB
3 - Start of script - verify=True
==================================== | =========== | ============
<class 'str | 13937 | 1.59 MB
<class 'dict | 2014 | 1.09 MB
<class 'code | 4445 | 626.77 KB
<class 'type | 563 | 588.95 KB
<class 'set | 147 | 144.16 KB
<class 'tuple | 1574 | 107.02 KB
<class 'wrapper_descriptor | 1213 | 94.77 KB
<class 'weakref | 1081 | 84.45 KB
<class 'abc.ABCMeta | 84 | 83.24 KB
<class 'builtin_function_or_method | 1030 | 72.42 KB
<class 'method_descriptor | 945 | 66.45 KB
<class 'int | 1891 | 56.13 KB
<class 'list | 314 | 53.05 KB
<class 'getset_descriptor | 689 | 48.45 KB
<class 're.Pattern | 87 | 44.62 KB
4 - 4/5 minutes into run - verify=True
==================================== | =========== | ============
<class 'str | 13936 | 1.59 MB
<class 'dict | 2014 | 1.09 MB
<class 'code | 4444 | 626.62 KB
<class 'type | 563 | 588.95 KB
<class 'set | 147 | 144.16 KB
<class 'tuple | 1573 | 106.91 KB
<class 'wrapper_descriptor | 1213 | 94.77 KB
<class 'weakref | 1081 | 84.45 KB
<class 'abc.ABCMeta | 84 | 83.24 KB
<class 'builtin_function_or_method | 1030 | 72.42 KB
<class 'method_descriptor | 945 | 66.45 KB
<class 'int | 1891 | 56.13 KB
<class 'list | 314 | 53.05 KB
<class 'getset_descriptor | 689 | 48.45 KB
<class 're.Pattern | 87 | 44.62 KB
The text was updated successfully, but these errors were encountered: