-
-
Notifications
You must be signed in to change notification settings - Fork 538
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
FastAPI deployment on Heroku socket.io errors #469
Comments
Is the basic FastAPI app working? E.g. what happens if you are commenting out nicegui/examples/fastapi/main.py Line 14 in 2213d4b
Also it would be interesting to see the output with the newest version of NiceGUI 1.1.10. We changed the websocket path to not collide with the python-socketio default... |
The FastAPI app works, yes. I just updated and the problem is unfortunately unchanged. |
Ok, I just tried it myself. Seems that pure socket.io is already causing the problem. Here a minimal setup Filename: Procfile
Filename: main.py import uvicorn
from fastapi import FastAPI
from fastapi_socketio import SocketManager
from fastapi.responses import HTMLResponse
app = FastAPI()
socket_manager = SocketManager(app=app)
@app.get("/", response_class=HTMLResponse)
async def index():
return """
<html>
<head>
<script src="https://cdn.socket.io/4.6.0/socket.io.min.js" integrity="sha384-c79GN5VsunZvi+Q/WObgk2in0CbZsHnjEqvFxC5DxHn9lTfNce2WW6h2pH6u/kF+" crossorigin="anonymous"></script>
<script>
var socket = io({path:"/ws/socket.io/"});
socket.on('connect', function() {
console.log('Connected!');
});
</script>
</head>
<body>
<h1>Socket.IO Example</h1>
</body>
</html>
""" Filename: requirements.txt
Filename: runtime.txt
|
Thanks for the example - that seems to work for the SocketIO issue, but it looks like I'm still getting 400 errors. However, with some of the chatter reduced in the logs, I got a nice side-by-side for running locally (succeeds) and deployment on Heroku (fails).
As you can see, it looks like it's failing when first attempting to establish the socket connection. Additionally, I get "Invalid session" at the very start of the logging each time the app is restarted. I've been digging into the problem to figure out how to fix it but I figure the additional context here will be useful. |
@krummja does my minimal example without NiceGUI work for you? |
Yes, without NiceGUI it works fine. |
That is strange. As I wrote in #469 (comment), my minimal example does not work on Heroku: Locally it works as expected. |
Oh no! The solution was so simple! When limiting the number of workers to 1, everything works as expected. Even with NiceGUI: Procfile
|
Good grief... Well, I'll take simple over the alternative. Thanks a bunch for looking into the issue! |
I had the same problem and fixed it with this solution. I've read that this can slow your app down though especially a large one. Do you know if this is the case and if so is there a way to compensate for this? |
It depends on what is meant by "large". NiceGUI (and FastAPI, and Starlette) are async frameworks. That means, no io-bound or cpu-bound tasks should be directly executed on the main thread but rather be "awaited". See https://fastapi.tiangolo.com/async/ for more details. |
The minimal FastAPI example provided in demos does not run when deploying to Heroku. On opening the UI page, it continuously drops connection and attempts to reconnect/reload the page. HTTP traffic in the developer inspector shows numerous 400 and 403 errors. In the Heroku logs, this section at the start provides some insight into what goes wrong.
I'm deploying with the following Procfile:
Configurations using
gunicorn
/WSGI have the same issue.Edit: I just realized it'd probably be helpful to link to the deployed page as well.
The text was updated successfully, but these errors were encountered: