I am trying to deploy a simple Python socketio server.
I’ve tested it locally and it works. But when I put it on fly.io my webpage client can never reach it and it crashes.
Here is my `server.py`
import socketio
import eventlet
print("Hello Fly.io!")
IP = "fly-global-services"
# IP = "127.0.0.1"
PORT = 5000
sio = socketio.Server(async_mode='eventlet',cors_allowed_origins='*')
app = socketio.WSGIApp(sio)
@sio.event
def connect(sid, environ):
print('new connection: ', sid)
@sio.event
def Client(sid, *data):
print("received message from client:",sid)
print("the contents of the message were:",*data)
@sio.event
def disconnect(sid):
print('disconnected from: ', sid)
eventlet.wsgi.server(eventlet.listen((IP, PORT)), app)
print("this should not print")
Here is my `requirements.txt`
python-socketio
eventlet
Here is my `Dockerfile`
ARG PYTHON_VERSION=3.7
FROM python:${PYTHON_VERSION}
RUN apt-get update && apt-get install -y \
python3-pip \
python3-venv \
python3-dev \
python3-setuptools \
python3-wheel
RUN mkdir -p /app
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# replace APP_NAME with module name
CMD ["python", "server.py"]
2022-04-17T16:03:47Z [info]Unpacking image
2022-04-17T16:03:49Z [info]Configuring firecracker
2022-04-17T16:03:49Z [info]Starting virtual machine
2022-04-17T16:03:49Z [info]Starting init (commit: 252b7bd)...
2022-04-17T16:03:49Z [info]Preparing to run: `python server.py` as root
2022-04-17T16:03:49Z [info]2022/04/17 16:03:49 listening on [fdaa:0:5a7f:a7b:2808:a612:7f97:2]:22 (DNS: [fdaa::3]:53)
2022-04-17T16:07:04Z [error]Error 1: Undocumented
--> v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1
The client:
(nothing)
Yes, in this case to: https://firstsocketio.fly.dev
with the line 37 of the html file: socket = io(address);
where address is https://firstsocketio.fly.dev generated from the form inputs
It appears that your server is not listening in the proper place. Can you change your “IP” constant to “127.0.0.1” or “0.0.0.0” and try to deploy?
Usually “Failed due to unhealthy allocations” means you fly.toml checks (in this case TCP checks) were not being successful therefore they assumed the deployment did not go right.
I am pretty much still stuck, with no idea why it is failing.
I want to believe it is not because of cors, since I’ve long dealt with that in the python code (documentation reference here). I just don’t understand why it works when I test elsewhere, for example hosting the server myself and still connecting with the page online hosted elsewhere. But it just won’t work on fly.io. I’d appreciate if you could help figure this out.
Right now, it’s set to only listen on 172.0.0.1, we connect from a non-local (but still private) IP so we can’t currently connect to your app. This causes health checks to fail.
Once you deploy with 0.0.0.0, you should check two things:
fly status --all to see if there are failing VMs
fly vm status <id> to look at exit codes or health check failures
This is not related to cors, it’s just our ability to talk to your application process. fly-global-services is only for UDP apps, not relevant to TCP.