We’re moving a rails app from Heroku to fly.io. We noticed that:
The app seems to restart frequently
When the app first starts up, we get a handful of these errors: “instance refused connection. is your app listening on 0.0.0.0:3000? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)”
I got help from fly.io support to resolve both, so I’ll post the answers here in case it helps others…
These settings allow fly.io to automatically spin machines down when load is lower, and spin them back up when there’s a need.
The reason for the “instance refused connection” errors is that the fly.io router begins routing requests to the machine right away, before Puma / Rails gets a chance to start up. The workaround here is to use the following settings in fly.toml:
[[http_service.checks]]
# Pick an appropriate wait period for your app, and add some buffer.
grace_period = "10s"
Quick question: when you get “instance refused connection” in the logs, are you also seeing errors from clients / browsers? The proxy will log that error while it does retries, so if all you’re seeing is logs and no client errors, you can safely ignore those.