refused connection to machine before app server finished starting


I have a clojure server that is slow to start up, and fly is refusing to connect because the server is not up yet. Is there a way to specify a delay before fly connects to the machine?

Here is the output from fly logs:

2024-01-21T18:48:09Z app[148ed195c93678] sin [info] INFO Starting init (commit: 8995e367)...                                                                                                                       
2024-01-21T18:48:09Z app[148ed195c93678] sin [info] INFO Mounting /dev/vdb at /data w/ uid: 0, gid: 0 and chmod 0755                                                                                               
2024-01-21T18:48:09Z app[148ed195c93678] sin [info] INFO Resized /data to 3204448256 bytes                                                                                                                         
2024-01-21T18:48:09Z app[148ed195c93678] sin [info] INFO Preparing to run: `java -Xint -jar rm-standalone.jar` as root                                                                                             
2024-01-21T18:48:09Z app[148ed195c93678] sin [info] INFO [fly api proxy] listening at /.fly/api                                                                                                                    
2024-01-21T18:48:09Z app[148ed195c93678] sin [info]2024/01/21 18:48:09 listening on [fdaa:5:89b3:a7b:187:dedd:6d36:2]:22 (DNS: [fdaa::3]:53)                                                                       
2024-01-21T18:48:09Z proxy[148ed195c93678] sin [info]machine started in 519.762869ms                                                                                                                               
2024-01-21T18:48:15Z proxy[148ed195c93678] sin [info]waiting for machine to be reachable on (waited 5.292465366s so far)                                                                              
2024-01-21T18:48:18Z proxy[148ed195c93678] sin [error]failed to connect to machine: gave up after 15 attempts (in 8.270759979s)                                                                                    
2024-01-21T18:48:18Z proxy[148ed195c93678] sin [error]instance refused connection. is your app listening on make sure it is not only listening on (hint: look at your startup logs, servers
 often print the address they are listening on)
2024-01-21T18:48:21Z app[148ed195c93678] sin [info]2024-01-21 18:48:21,997 [main] INFO  migratus.core: Starting migrations
2024-01-21T18:48:24Z app[148ed195c93678] sin [info]2024-01-21 18:48:24,934 [main] INFO  migratus.core: Ending migrations
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,260 [main] INFO  rm.config: Server started on port: 8080
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,365 [main] INFO  org.eclipse.jetty.server.Server: jetty-11.0.18; built: 2023-10-27T02:14:36.036Z; git: 5a9a771a9fbcb9d36993630850f612581b78c
13f; jvm 21.0.1+12-LTS
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,492 [main] INFO  org.eclipse.jetty.server.handler.ContextHandler: Started o.e.j.s.ServletContextHandler@6cd31e5f{/,null,AVAILABLE}
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,504 [main] INFO  org.eclipse.jetty.server.AbstractConnector: Started ServerConnector@44b99f09{HTTP/1.1, (http/1.1)}{}
2024-01-21T18:48:25Z app[148ed195c93678] sin [info]2024-01-21 18:48:25,509 [main] INFO  org.eclipse.jetty.server.Server: Started Server@1737acc0{STARTING}[11.0.18,sto=0] @15717ms
1 Like


fly-proxy only connects to your instance in case it is healthy. You can specify a healthcheck for your app. You can configure the healthcheck to only pass once your app is ready to serve requests.

You can use services.http_checks or services.tcp_checks.

Thanks for the response. I’ve tried setting a healthcheck, but the deployment keeps getting stuck at the healthcheck stage. Sometimes it passes, but then I can’t reach the site. When I run wget http://localhost:8080 on the machine through ssh console, I get this output:

Connecting to localhost:8080 ([::1]:8080)
Connecting to localhost ([::1]:443)
wget: can't connect to remote host: Connection refused

Is my config file correct? Here’s my fly.toml file:

app = "rmrt1n"
primary_region = "sin"


PORT = "8080"

internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

interval = "30s"
timeout = "5s"
grace_period = "120s"
method = "get"
path = "/"

cpu_kind = "shared"
cpus = 1
memory_mb = 1024

source = "rmrt1n_storage"
destination = "/data"

The server usually takes around 30s to start on my machine.

Connections on the local interface (localhost) are not affected by healthchecks, services, or any other fly.toml configuration. If the port 8080 on localhost refuses to connect, it probably means your application isn’t ready to serve connections.

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