Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Need alternative HealthCheck #2630

Open

Description

@Simbiat

What happened?

Thanks to my recent task to check that my MariaDB backups are working fine (had issues with Ofelia not firing, hence I switched to Supercronic), I noticed issues on my server to day. I saw an hour old error.flag file, which normally creates an email, which is sent by a job, that's triggered by Supercronic on FrankenPHP container, if that container is healthy. But it was not triggered, because the container was not healthy. Although it seemed to be working fine.

Current healthcheck calls curl -f http://localhost:2019/metrics, and I did that. I got a flood of entries like

caddy_rate_limit_process_time_seconds_sum{key="130.180.236.170/32",zone="reads"} 5.0729e-05
caddy_rate_limit_process_time_seconds_count{key="130.180.236.170/32",zone="reads"} 1
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.001"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.005"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.01"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.025"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.05"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.1"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.25"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="0.5"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="1"} 2
caddy_rate_limit_process_time_seconds_bucket{key="130.180.236.176/32",zone="reads",le="+Inf"} 2
caddy_rate_limit_process_time_seconds_sum{key="130.180.236.176/32",zone="reads"} 7.129200000000001e-05

It continued for like 20 seconds, when I broke it. I did a docker inspect --format='{{json .State.Health}}' frankenphp and it last healthcheck exceeded 30s timeout. But that's not all: looks like this also resulted in OOM that killed mariadb container. I do not have hard proof of that, but OOM did kill mariadb, and the timing is mighty suspicious. I see there was also a #439, which was caused by a memory leak, but it does suggest that healthcheck can cause a spike in memory usage, and if it will trigger OOM-killer, mariadb will be selected since it uses the most of RAM.

The entries are likely caused by https://github.com/mholt/caddy-ratelimit so I disabled metrics there for now (at least), but... Someone may need these metrics. Maybe not from this plugin, but from something else, that can also result in growth of the output from /metrics endpoint. Maybe not to the same extent, as rate-limiter, but depending on what else is happening on the server even a small increase in size can trigger an OOM or slowness of output of the metrics and you get issues.

As such, I am raising this ticket so that an alternative healthcheck is considered in the FrankenPHP Docker image. And since this is built into FrankenPHP image, I am raising it for FrankenPHP. It also may be worthwhile to have something that not only checks that Caddy is up, but that PHP interpreter is working, too. For Caddy side it looks like /config endpoint is the most neutral, but my config is 122KBs, which is relatively large, too, so may not be ideal.

Build Type

Docker (Debian Trixie)

Worker Mode

No

Operating System

GNU/Linux

CPU Architecture

x86_64

PHP configuration

phpinfo() output
N/A

Relevant log output

Relevant log output
N/A

Activity

  1. added
    bug
    on Aug 31, 2026
  2. AlliBalliBaba commented on Sep 2, 2026

    @AlliBalliBaba
    Contributor

    We could add a custom admin api endpoint like http://localhost:2019/frankenphp/health that hits a PHP thread, but that would probably not cover your case since it skips all the Caddy middlewares like rate-limiting.

    Best case scenario is probably having a custom health check endpoint for your application, not sure if baking in a public endpoint for health-checks is a good idea.

  3. Simbiat commented on Sep 5, 2026

    @Simbiat
    Author

    So what I did as a workaround (not sure if I'd consider this the best solution) is add a server in my Caddy's JSON config:

            "healthcheck": {
              "listen": [
                ":2026"
              ],
              "routes": [
                {
                  "match": [
                    {
                      "remote_ip": {
                        "ranges": [
                          "127.0.0.1/32",
                          "::1/128"
                        ]
                      }
                    }
                  ],
                  "handle": [
                    {
                      "handler": "vars",
                      "root": "/healthcheck"
                    },
                    {
                      "handler": "rewrite",
                      "uri": "/healthcheck.php"
                    },
                    {
                      "handler": "php"
                    }
                  ],
                  "terminal": true
                }
              ]
            }

    This setup allows access to 2026 port only from within the container and rewrites any kind of request to healthcheck.php, which has contents like:

    <?php
    
    declare(strict_types=1);
    
    http_response_code(200);

    And then in Dockerfile I've added these lines:

    RUN mkdir /healthcheck
    COPY healthcheck.php /healthcheck/healthcheck.php
    
    HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 CMD ["curl", "-f", "http://localhost:2026"]

    This allows to check that both network side and PHP handler are working. At least, theoretically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions