Can't connect to nats server via flycast proxy

Hi all, I deployed a nats server instance using the official nats image and trying to connect to it from another app which is just a bun server using the @nats-io/transport-node npm library.

Here’s my config for the nats server:

# fly.toml app configuration file generated for coindozer-nats on 2024-11-07T17:45:59+08:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'my-nats'
primary_region = 'sin'

[build]
image = 'nats'

[[services]]
protocol = 'tcp'
internal_port = 4222
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
[[services.ports]]
port = 4222
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

However, the bun server keeps running into timeout errors emitted by the nats client library while trying to connect to the nats server. I’m properly using my-nats.flycast:4222 as the connection string when using the library. Should also note that the bun server is able to properly resolve the my-nats.flycast address through DNS after inspecting using Bun.dns.resolve. Is it not possible to use nats behind a flycast proxy? can I only use private 6pn addresses? thank you.

I notice you have auto_stop_machines set. Is your nats server stopping automatically and taking too long to start accepting connections when the bun server tries to connect to it?

Steve

Hi Steve, appreciate the reply! I don’t think the nats server started up at all to begin with, since I was never able to connect to it and I know that by default fly apps start asleep and only awaken when the proxy activates it.

I should also add here that I switched to using .internal addresses which worked fine but this meant that the nats server can’t scale to zero.

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