Trouble getting UDP to work

I want to use a UDP app, and somehow receiving and replying to packets doesn’t work. I had it work once, for a certain deployment, but can’t remember what region that was in. For now, I can reliably reproduce the problem with ncat.

Dockerfile:

FROM alpine:latest

RUN apk add nmap-ncat net-tools

EXPOSE 10000/udp

ENTRYPOINT [ "ncat", "-u", "-4", "-v", "-l", "-c", "cat", "-k", "fly-global-services", "10000" ]

fly.toml:

app = "ncat-test"

kill_signal = "SIGINT"
kill_timeout = 5

[[services]]
  internal_port = 10000
  protocol = "udp"

  [[services.ports]]
    port = "10000"

After the app is successfully deployed, I run ncat -u -4 -v ncat-test.fly.dev 10000 and would expect any input to be echo’ed back by the server, which isn’t happening. On the server side, due to the -v flag, there should be a line Ncat: Connection from X.X.X.X., but nothing is printed.

Am I doing something wrong? What’s the problem here?

Sec, let me try to reproduce this.

FWIW: The EXPOSE line in the Dockerfile won’t make a difference (the configuration is entirely in your fly.toml).

Ok, so I did this:

FROM alpine
RUN apk update && apk add nmap-ncat net-tools tcpdump bind-tools
CMD tail -f /dev/null

I ran flyctl launch, and then edited the fly.toml to include:

[[services]]
  internal_port = 10000
  protocol = "udp"
  [[services.ports]]
    port = "10000"

[[services]]
  internal_port = 5000
  protocol = "udp"
  [[services.ports]]
    port = "5000"

(Just in case it was port-specific behavior).

I deployed, then I flyctl ssh console'd into the instance.

I ran ncat -u -4 -v -l -c cat -k fly-global-services 10000, then, from my desktop, I ran nc -u <myapp>.fly.dev (nc is the one true netcat).

It worked; here’s a transcript:

Client:

> $ nc -u testapp.fly.dev 10000                                                                                                                         
helu
helu

Server:

/ # ncat -u -4 -v -l -c cat -k fly-global-services 10000
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on 172.19.2.243:10000
Ncat: Connection from 50.205.163.67.
Ncat: Listening on 172.19.2.243:10000

You’re completely right, my original app now works after a new launch as well, it just took a few minutes until UDP connections worked. Thanks for looking into this anyway and the super-fast response!

Just for the record, it shouldn’t take many minutes for connectivity to your app to work! If that happens, let us know.

Hi there, replying to this old post because I’m having the exact same problem - intermittent UDP connectivity after a machine is auto started. I have set fly-global-services accordingly, pushed the same internal port, provided a dedicated IP, etc. It works… sometimes. Not really sure what’s causing this.

I am running a game server that communicates over tcp/459 which is the port that will auto-start the machine. Activity on udp/24454 should not start/stop the machine and there should only ever be one machine started.

Here is the relevant part of my fly.toml

[[services]]
  protocol = 'tcp'
  internal_port = 25565
  auto_stop_machines = 'off'
  auto_start_machines = true
  min_machines_running = 0

  [[services.ports]]
    port = 459

  [[services.tcp_checks]]
    interval = '15s'
    timeout = '2s'
    grace_period = '1s'

[[services]]
  protocol = 'udp'
  internal_port = 24454
  auto_stop_machines = 'off'
  auto_start_machines = false
  min_machines_running = 0

  [[services.ports]]
    port = 24454

[[restart]]
  policy = 'never'

[[vm]]
  memory = '8gb'
  cpu_kind = 'performance'
  cpus = 1

can you tell me please how exactly you did that?

It’s specific to the configuration for the game server. There is a property in their config file to override the bind address. It works intermittently so I don’t think it’s a problem with the config. Though the last couple of days it seems to have been working more consistently. Maybe there was a Fly.IO service outage?