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.