overthesun / simoc

A scalable model of an interactive, off-world community
https://ngs.simoc.space/
GNU General Public License v3.0
2 stars 1 forks source link

Upgrade to websocket transport on beta/ngs #263

Closed ezio-melotti closed 10 months ago

ezio-melotti commented 1 year ago

socketio supports two types of transport: websockets and HTTP long-polling:

Even if most browsers now support WebSockets (more than 97%) [HTTP long-polling] is still a great feature as we still receive reports from users that cannot establish a WebSocket connection because they are behind some misconfigured proxy.

I noticed that when using `simoc-sam` locally, the transport is automatically upgraded to use websockets (click to see screenshot). ![image](https://user-images.githubusercontent.com/25624924/206867701-6b115790-4ac0-4851-beea-8e9238274ec8.png)

This however doesn't happen for the sim backend. I spent some time investigating and it seems likely that we have some misconfiguration in both nginx (used locally and on beta) and traefik (used on GCP).

The socketio docs have a section about sockets stuck in HTTP long-polling that link to another page with a recommended nginx configuration. However we already have something similar in

https://github.com/overthesun/simoc/blob/87dbc5c1085e37553fcc494ff04f41c02f9e75c9/nginx/proxy_ws_params#L1-L6

which is then imported in

https://github.com/overthesun/simoc/blob/87dbc5c1085e37553fcc494ff04f41c02f9e75c9/nginx/simoc_nginx.conf.jinja#L75-L79

even though it doesn't seem to work.

The traefik config files don't seem to mention websockets.


I also noticed that we are disabling CORS checks on the sim backend, so once we fixed these issues we should look into updating this with something stricter: https://github.com/overthesun/simoc/blob/87dbc5c1085e37553fcc494ff04f41c02f9e75c9/simoc_server/views.py#L34-L35


I also tried/investigated other things:

ezio-melotti commented 10 months ago

I fixed this in #446:

Without an additional websocket lib, our socketio connection relies on long polling. Starting from python-engineio 4.7.1, simple-websocket has been added, but it seems to have issues with gevent/gunicorn/flask. gevent-websocket seems to work fine.

We should still look into having stricter CORS checks.