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

Sanic stops working after trying to open a WS connection #2904

Open
1 task done
cnicodeme opened this issue Jan 18, 2024 · 2 comments
Open
1 task done

Sanic stops working after trying to open a WS connection #2904

cnicodeme opened this issue Jan 18, 2024 · 2 comments
Labels

Comments

@cnicodeme
Copy link
Contributor

cnicodeme commented Jan 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I recently updated my machine to the latest OS (Fedora 39). The codebase was working well before, so I suspect this might be related to the Python version:

Python: 3.12.1

Code snippet

from sanic import Request, Websocket, Sanic
from sanic.response import text

app = Sanic("MyHelloWorldApp")


@app.websocket("/stream")
async def feed(request: Request, ws: Websocket):
    data = "hello!"
    print("Sending: " + data)
    await ws.send(data)
    data = await ws.recv()
    print("Received: " + data)


@app.get('/')
async def hello(request):
    return text("Hello, world.")

if __name__ == "__main__":
    app.run(port=5000, debug=True)

Connecting with Firefox and with the following basic code:

let ws = new WebSocket("ws://127.0.0.1:5000/stream");
ws.onerror = (e) => {
  console.log(e);
}
ws.onopen = () => {
  console.log("connected");
  ws.send("hello");
}

Expected Behavior

Steps to reproduce the issue:

  1. Go to http://127.0.0.1:5000/
  2. See the "Hello world message"
  3. Open the console and paste the above javascript
  4. An error is shown in the console: "Firefox can't establish a connection with the server at ws://127.0.0.1:5000/stream" (The message might differ as I have it in French and translated it)
  5. Refresh the page : The page hangs, Sanic doesn't answer any requests anymore

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

Linux

Sanic Version

Sanic 23.6.0; Routing 23.12.0

Additional context

From the MOTD:

  • mode: debug, single worker
  • server: sanic, HTTP/1.1
  • platform: Linux-6.6.11-200.fc39.x86_64-x86_64-with-glibc 2.38
@cnicodeme cnicodeme added the bug label Jan 18, 2024
@cnicodeme
Copy link
Contributor Author

For information, I just tried with Python 3.10.13, and it works fine.

Some changes in recent Python's version must impact how Sanic behave, but my lack of deep understanding of the internals of Sanic blocks me for identifying the root cause of the problem.

@ahopkins
Copy link
Member

ahopkins commented Apr 7, 2024

image

This is not my experience. Granted, I am on the latest main, but I don't think there was anything that would have changed.

Are you still experiencing this?

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

2 participants