Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-socketio (websocket transport)] sanic.exceptions.ServerError: Invalid response type None (need HTTPResponse) on Disconnect #2572

Open
4n1qz5skwv opened this issue Oct 14, 2022 · 6 comments
Labels

Comments

@4n1qz5skwv
Copy link

Requirements:

sanic==22.9.0
python-socketio==5.7.1

Code:

import sanic
import socketio

app = sanic.Sanic("app")


@app.on_request
async def print_urls(request):
    print(f'>>>> {request.url}')


@app.route("/")
async def handler(_):
    return sanic.response.html(
        '''<!doctype html>
        <html lang="en">
           <head></head>
           <body>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
              <script>
                 var socket = io({
                     path: "/socket.io/",
                     transports: ["websocket"]
                 });
              </script>
           </body>
        </html>''')


sio = socketio.AsyncServer(async_mode='sanic', logger=False, engineio_logger=False)
sio.attach(app)


@sio.event
def connect(sid, *_):
    print(f'>> Connected Successfully: {sid}')


@sio.event
def disconnect(sid):
    print(f'>> Disconnected Successfully: {sid}')


if __name__ == '__main__':
    app.run(access_log=False)

Error:

Error.mp4

More:
Problem occurs only after disconnection when websocket transport is used. Details in video. Everything else is working Perfectly.

@4n1qz5skwv 4n1qz5skwv added the bug label Oct 14, 2022
@4n1qz5skwv
Copy link
Author

Old related issues:

#2105

@ahopkins
Copy link
Member

I can try and take a look next week. Did you try as a hack to return a dummy response object from the disconnect callback?

@ahopkins
Copy link
Member

I'll be honest, I have no clue how that is "attaching" to Sanic and plugging into the router for example 🤷‍♂️

@ChihweiLHBird
Copy link
Member

I couldn't reproduce the issue with latest Sanic (main branch), latest python-socketio (5.11.2), and Python 3.11 on Linux.

@catdogmat
Copy link

I also can't reproduce the issue with latest Sanic (v24.6.0), latest python-socketio (5.11.3) and Python 3.11.8 on Windows. I believe this is fixed!

@catdogmat
Copy link

This is fixed and can be closed!
See: miguelgrinberg/python-socketio@287d6ed

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

No branches or pull requests

4 participants