Socket.io connection being canceled on fly.io

I have a single fly.io machine running my Python backend app, which does text-to-speech audio streaming using Socket.io to stream the audio chunks to the Next.js frontend.
Locally the audio streaming over websockets works, but when I deploy the backend to fly.io and frontend to Vercel - the audio streaming randomly stops after ~2 seconds.

My Python backend uses RealtimeTTS GitHub - KoljaB/RealtimeTTS: Converts text to speech in realtime
with Azure Speech Services.

It’s almost like something forces the audio streaming to stop after a few seconds. Could the fly.io loadbalancer or proxy be the reason here?

My fly.io config:

app = 'staging-polyglotpal'
primary_region = 'gru'

[processes]
app = "./main.py"
otelcollector = "otelcol-contrib --config /etc/otelcol/otel-config.yaml"

[build]
  dockerfile = "Dockerfile"

[[services]]
  name = "app"
  processes = ["app"]
  internal_port = 8000
  protocol = "tcp"
  auto_stop_machines = "suspend"
  auto_start_machines = true
  min_machines_running = 1
  force_https = true

[services.concurrency]
  hard_limit = 20
  soft_limit = 15

[[services.ports]]
    handlers = ["tls", "http"]
    tls_options = { "alpn" = ["h2", "http/1.1"], "versions" = ["TLSv1.2", "TLSv1.3"] }
    port = 443

[[services.ports]]
    handlers = ["http"]
    port = 80

[[services.http_checks]]
  interval = "10s"
  grace_period = "30s"
  method = "get"
  path = "/api/healthcheck/status"
  protocol = "http"
  timeout = "5s"
  tls_skip_verify = true

[[services]]
  name = "otelcollector"
  processes = ["otelcollector"]
  internal_port = 40000

[[services.tcp_checks]]
  interval = "10s"
  grace_period = "30s"
  timeout = "5s"

[[vm]]
size = "performance-1x"
#size = "shared-cpu-1x"
cpus = 1
memory = "2gb"
processes = ["app"]

[[vm]]
size = "shared-cpu-1x"
cpus = 1
memory = "512mb"
processes = ["otelcollector"]

Socket.io config:

ping_interval=45,
ping_timeout=120,
transports: [“websocket”],
forceNew: false,
reconnection: true,
reconnectionAttempts: 3,
reconnectionDelay: 3000,
timeout: 10000,

I’m quite stuck right now and would really appreciate some feedback.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.