Dockerized Clojure app always failing healthchecks (tcp and http)

I have configured my Ring web server to run on 0.0.0.0:8080. My service is up and working fine, but health checks always fail, which is annoying.

Please see my fly.toml and Dockerfile below.

# fly.toml app configuration file generated for stckd on 2023-12-17T08:44:54Z
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "stckd"
primary_region = "lhr"
kill_signal = "SIGINT"
kill_timeout = "5s"

[experimental]
  auto_rollback = true

[build]

[env]
  PORT = "8080"
  ENVIRONMENT = "prod"

[http_service]
  internal_port = 8080
  force_https = true
  min_machines_running = 1
  processes = ["app"]

[[services]]
  protocol = "tcp"
  internal_port = 8080
  processes = ["app"]

  [[services.ports]]
    port = 80
    handlers = ["http"]
    force_https = true

  [[services.ports]]
    port = 443
    handlers = ["tls", "http"]
  [services.concurrency]
    type = "connections"
    hard_limit = 25
    soft_limit = 20

  [[services.http_checks]]
    interval = 10000
    grace_period = "10s"
    method = "get"
    path = "/health"
    protocol = "http"
    timeout = 2000
    tls_skip_verify = false

[[vm]]
  cpu_kind = "shared"
  cpus = 1
  memory_mb = 1024
FROM clojure:latest

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY deps.edn /usr/src/app/
RUN clj -Sforce < /dev/null

COPY . /usr/src/app

RUN clj -A:depstar -m hf.depstar.uberjar stckd.jar

EXPOSE 8080

ENTRYPOINT ["java", "-cp", "stckd.jar", "clojure.main", "-m", "server"]

Any pointers will be gratefully received!

It looks like you only want to expose an HTTPS service, in which case, you can use just an [http_service] section, and ditch the [[services]] section.

My hunch here is that the fact you have overlapping definitions is a problem. Based on the fact your health check is failing, I’m guessing that the [[services]] section is being overridden by the [http_service] definition, and so your health check config is not being paid any attention.

Could you try migrating the config you have under [[services]] to [http_service]? I think the following would do the trick:

app = "stckd"
primary_region = "lhr"
kill_signal = "SIGINT"
kill_timeout = "5s"

[experimental]
  auto_rollback = true

[build]

[env]
  PORT = "8080"
  ENVIRONMENT = "prod"

[http_service]
  internal_port = 8080
  force_https = true
  min_machines_running = 1
  processes = ["app"]

  [http_service.concurrency]
    type = "connections"
    hard_limit = 25
    soft_limit = 20

  [[http_service.checks]]
    interval = 10000
    grace_period = "10s"
    method = "get"
    path = "/health"
    protocol = "http"
    timeout = 2000
    tls_skip_verify = false

[[vm]]
  cpu_kind = "shared"
  cpus = 1
  memory_mb = 1024

By the way, according to fly config check, interval = 10000 = 10µs (similarly for timeout), and it will be raised to 1 second, so might be worth specifying as e.g. interval = "10s" for clarity.

Let me know if that doesn’t work!

Awesome, that worked! Thank you!

I changed timeout to "2s" because I was getting an invalid duration error, but apart from that the config above solved it. Thanks!

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