Skip to content

Conversation

@smeng9
Copy link

@smeng9 smeng9 commented May 12, 2025

No description provided.

@kgaughan
Copy link
Member

Could you add tests to cover this?

@smeng9
Copy link
Author

smeng9 commented May 13, 2025

Hi @kgaughan

Tests added!

@smeng9
Copy link
Author

smeng9 commented Jun 16, 2025

Hi @kgaughan ,

Any chance this can be reviewed soon?

@digitalresistor
Copy link
Member

How does the hand-off back to Waitress happen? This completely breaks the way that waitress handles sockets/WSGI communication.

I don't think this is a good idea, nor one that the Pylons Project would like to support. This will tie up the thread for the entire time the WebSocket is alive, which is just a bad idea. Waitress was never built with this in mind.

The test you added is also not an appropriate test, it just adds a new socket to the WSGI environment, not the one that is passed in, does not show the upgrade process or making sure that that this won't break anything else.

@smeng9
Copy link
Author

smeng9 commented Jul 6, 2025

Hi @digitalresistor

Let me explain how this will work. Currently waitress does not support websocket due to not exposing the raw socket object to request handlers. We use a very popular library called simple-websocket, and we want it to be able to access the socket object and handle the communication (the upgrade process) for us. https://github.com/miguelgrinberg/simple-websocket/blob/main/src/simple_websocket/ws.py#L248 .

As you can see, if we want to handle the long running communication, there has to be some thread running. Waitress supports multi threading, and it is user's responsibility to add more thread. Also, for the added extra property waitress.socket if user is not using it in normal http requests, it will not have any negative effect and break other things.

If you were to introduce the websocket to your project, what would be your recommended approach?

@smeng9
Copy link
Author

smeng9 commented Nov 14, 2025

Hi @digitalresistor

It has been a while since this merge request is opened. I have also did some research how websocket should be supported through wsgi.

Mainly the socket objects needs to be passed as custom extensions to the request https://stackoverflow.com/questions/75538581/does-pythons-wsgi-specification-have-anything-to-say-about-websockets

Other mainstream wsgi handlers already added the support, but they are only available on Linux platform. As waitress natively supports Windows, I hope we can push this forward a bit.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants