'HTTP Over Unix Domain Sockets (UDS) using Flask - BrokenPipeError: [Errno 32] Broken pipe
I am trying to set up a Flask server using UDS, but am having trouble sending my second HTTP request.
I start up Flask using UDS by specifying:
self.flask_app.run(host="unix://" + socket_file, port=None)
A client-side code snip looks pretty standard, something like this:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(socket_file)
s.send(b"GET /ping HTTP/1.1\r\n\r\n")
# simplified a bit, actual code loops until all the data is returned
data = s.recv(1024)
# at this point data contains the entire, correct http response
# now I want to make a second request by doing
s.send(b"GET /ping HTTP/1.1\r\n\r\n")
And I get:
BrokenPipeError: [Errno 32] Broken pipe
If I try to call s.connect() again, I get:
OSError: [Errno 106] Transport endpoint is already connected
If I make and use a whole new socket object, it works.
I suspect that Flask is automatically closing the connection when it responds, but I'm not sure how to prove it or stop it from doing that.
Any advice to fix or diagnose this would be helpful!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
