Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.
This repository was 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

Description

@dhdaines

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): Kludex/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...

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions