Closed ekw closed 2 years ago
I'm not sure if this can be fixed. The issue happens because Flask, which does not recognize WebSocket requests, tries to issue a standard HTTP response when the connection ends.
OK, thanks for looking into it. Do the reason and message parameters in socket close function do anything at the moment (accessible by client)?
I've made some improvements. Could you please test the main branch of this repo and report back?
Here is a summary:
It works, thank you! I am using gunicorn proxied by nginx.
First off, the example echo server example works for me. But when I try to modify it for my needs, I get an "Invalid frame header" error in browser at the end of the connection. Instead of a forever loop as in the echo example, I want to make a connection, send data, receive data and end the connection. I can send and receive data fine, but always get an "Invalid frame header" error in the browser at the end of the connection. My websocket endpoint is this:
On the client side:
I see the "HI" on the server, and I see all the integer data on the client. But the browser gets an error after the integer data is sent. It doesn't matter how many sends I do from the server, all the data is received by the client fine. It's only at the end that I always get an error on the browser.
On Chrome, the error is "Invalid frame header". On Firefox, the error is "The connection to wss://host/ws was interrupted while the page was loading."
I am using: Python 3.8.10 gunicorn 20.1.0 gevent 21.12.0 nginx 1.18.0
gunicorn is being proxied by nginx. (As I'm detailing these versions, I now wonder if it's gunicorn/nginx not closing the connection properly.)
Does anyone know how to prevent the error from occurring?
edit: I took nginx and wss out of the equation and the error still occurs.