Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

socketio_path is incorrect in call to socketio.ASGIApp since FastAPI 0.109.0 / Stalette 0.33.0, breaking, well, everything #52

Open
dhdaines opened this issue Apr 4, 2024 · 1 comment

Comments

@dhdaines
Copy link

dhdaines commented Apr 4, 2024

The default mounting point of /ws/socket.io no longer works correctly for quite some time now, because of this change to Starlette (which, apparently, is just following the ASGI spec): encode/starlette#2413 (reply in thread)

First, you will have noticed that your JavaScript code using socket.io gives lots of 404 errors (or 403 errors, perhaps) and you will have tried to fix them by doing this:

var magicalMysteryOptions = { path: '/ws/socket.io', transports: ['websocket', 'polling', 'flashsocket']};
var conversionSocket = io(magicalMysteryOptions);

But, sadly, now you have another problem, which is a very large stacktrace on the server side with this in it:

RuntimeError: Expected ASGI message 'websocket.accept', 'websocket.close', or 'websocket.http.response.start' but got 'http.response.start'.

You have two choices, either you can downgrade to fastapi==0.108.0 (not recommended), or you can add a socketio_path argument to your SocketManager constructor:

socket_manager = SocketManager(
    app=app,
    socketio_path="/ws/socket.io",
)

This needs to be fixed in fastapi-socketio so that it passes the full path to socket.io (that is, prefixed with the mount location) in the ASGIApp constructor, and then fastapi-socketio needs to depend on at least the versions of FastAPI and Starlette mentioned above.

Since just joining mount_location and socketio_path will conflict with the workaround above, it would probably be a good idea to respect an absolute socketio_path if specified...

@dhdaines
Copy link
Author

dhdaines commented Apr 4, 2024

This is probably the same issue as #51 and #48 and maybe others

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant