Closed sn1572 closed 3 years ago
Here's some additional info. This issue does not seem to occur when using the requests library, so it may be browser-related. By examining the request header that Chrome logs, I was able to send an identical request like this:
import requests
def get_chunk_1():
URL = 'http://192.168.1.73:5000/shared/Gopro/GH010004.mp4'
response = requests.get(URL,
headers={'Accept': '*/*',
'Accept-Encoding': 'identity;q=1, *;q=0',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Connection': 'keep-alive',
'Cookie': 'hide-dotfile=no; session=<insert nasty hash here>',
'Host': '192.168.1.73:5000',
'Range': 'bytes=0-',
'Referer': 'http://192.168.1.73:5000/shared/Gopro/',
'User-Agent': 'Mozilla/5.0 (X11; CrOS x86_64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.199 Safari/537.36'
}
)
return(response)
Since I am trying to stream .mp4 videos, a sufficient test of functionality was to do this:
with open('test.mp4', 'wb') as f:
f.write(response.content)
and then verify that the video plays normally on my Chromebook, which it does. Checking the server logs verifies that it is providing the content as intended (you can see "yielding x byes" messages without interruption).
Furthermore, looking through Chrome logs I see an error NOTREACHED which is "always a code error" to paraphrase the Chrome dev tools. I would blame Chrome entirely except that we can't get Firefox to work either. :)
Still investigating.
This seems to be related: https://support.google.com/chrome/thread/25510119?hl=en
If true, Chrome issues a request for the whole file (bytes=0-) then intentionally breaks the connection at the TCP/IP level when it's read what it wants. After that it issues another request for the next chunk.
This is fixed now - not a wsgi issue. Turns out Chrome asks for the whole file (bytes 0-) but actually won't accept a response with too many bytes. This line of code caused Chrome to behave as expected, where max_length = 1<<20
.
if max_length and length > max_length:
length = max_length
Hello all. I have a small web app that wants to stream video files, but encounters broken sockets / connection resets while trying to transfer .mp4 files.
Note: Using Flask and uwsgi by themselves - no Nginx etc.
Here is a snippet from the logs:
and it goes on like that for a while. This is the function that is responsible for generating the data stream (ignore the ptr_to_bytes_read, this is a code artifact that doesn't currently do anything):
What's odd here is that streaming_response works fine when delivering .jpg image files, but it behaves kind of strangely when streaming audio. It sounds like the track starts playing twice, with one copy delayed slightly.
I've read all the usual threads online about how to fix broken pipe / connection reset issues and so far nothing's worked. Any help would be greatly appreciated.