You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I noticed you've added mmap to the code, which is great!
Unfortunately, it breaks consuming http streams, because urllib3 raw streams (urllib3.response.HTTPResponse) also (surprisingly) have a fileno!
So we get an exception:
inget_memoryview(data)
98# Handle file object opened in 'rb' mode99ifhasattr(data, "fileno"):
-->100mm=mmap.mmap(data.fileno(), 0, access=mmap.ACCESS_READ)
101returnmemoryview(mm)
103# Handle BufferedReaderOSError: [Errno22] Invalidargument
I've checked the set difference of attributes of a binary file handle and a HTTPResponse, and these attributes are (on my macos machine) exclusively available on files:
I'm not sure if I have the time, but if so I'll happily create a PR.
The easiest fix is of course to simply reject those streams.
(geturl seems like an attribute that is very, very unlikely to be present on file handles, but can be swapped of course depending on how strict the check should be):
if hasattr(data, "fileno") and not hasattr(data, 'geturl'):
But to be honest, it seems like a loss to exclude any and all binary streams. A better option would be to properly support them. That means either creating a separate code path bypassing memoryviews entirely (as was the case about a year ago).
Or, if you think that even streams might benefit from memoryviews, we could transform each chunk read from the stream.
Hi, I noticed you've added mmap to the code, which is great!
Unfortunately, it breaks consuming http streams, because urllib3 raw streams (
urllib3.response.HTTPResponse
) also (surprisingly) have a fileno!So we get an exception:
I've checked the set difference of attributes of a binary file handle and a HTTPResponse, and these attributes are (on my macos machine) exclusively available on files:
So it may be worth either switching the check or alternatively adding an extra condition that prevents mmap on
urllib3.response.HTTPResponse
objects.Cheers!
The text was updated successfully, but these errors were encountered: