The API isn't responding but the pod is healthy: a single connection filled the PHP-FPM pool
Requests trying to connect to an unreachable service keep PHP-FPM workers waiting forever. Once the pool is full, the API stops completely. Diagnosis and protection with request_terminate_timeout.
The uptime monitor reported DOWN for a test API. The pod was Running, no restarts, CPU and memory low. But every request was timing out. It had started a few hours after we shut down an old, unused server.
Symptoms
- The pod is up, and its liveness probe (TCP or a simple file) passes.
- HTTP requests go unanswered or return 502/504.
- This warning in the PHP-FPM log:
WARNING: [pool www] server reached pm.max_children setting (5), consider raising it
Why does it happen?
One of the application's endpoints, on a request that came in every hour, was trying to connect to an old database that no longer existed. Since there was no network path to the target, the connection neither succeeded nor failed quickly. On the PHP side no connection timeout was set, and on the FPM side there was no request_terminate_timeout.
So every hour, one FPM worker got stuck. In a small pool with max_children=5, after five hours there were no idle workers left and the API stopped completely. Since the pod itself looked healthy, Kubernetes did nothing.
Diagnosis
# Pool status (if pm.status_path is enabled)
kubectl exec <pod> -- sh -c 'SCRIPT_NAME=/status SCRIPT_FILENAME=/status REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000'
# What are the stuck workers waiting on? SYN-SENT = unanswered connection attempt
kubectl exec <pod> -- ss -tnp state syn-sent
# if ss isn't available, look from the node into the pod's network namespace:
# nsenter -t <pid> -n ss -tnp state syn-sent
If you see connections waiting in SYN_SENT together with "active processes = max_children", the problem isn't a lack of resources; it's waiting with no end.
Fix
Right away: restart the pod so the stuck workers are freed. This only resets the clock; it isn't a fix.
Protection on the infrastructure side: give FPM an upper limit, so no request can hold a worker forever.
; zz-timeout.conf (as a ConfigMap under /usr/local/etc/php-fpm.d/)
[www]
request_terminate_timeout = 600s
The zz- prefix makes sure the file is read last, so it overrides the existing pool settings.
Lasting fix on the application side:
- Remove the integration that's no longer used from the settings.
- Give every external connection a short connection timeout (e.g. 5 s). Keep it separate from the query timeout, which may run longer.
- Tie the liveness/readiness check to an endpoint that actually goes through PHP. That's the only way it will notice a full pool.
Takeaway
Before shutting down a server, look for the answer to "who connects to this?" not only in production but also in the settings of test environments. Every external call without a timeout will, sooner or later, lock up the whole pool.
Checklist
- [ ] Is
request_terminate_timeoutset in the FPM pools? - [ ] Do the database and HTTP clients have a connection timeout?
- [ ] Does the health check go through PHP?
- [ ] Have the addresses of decommissioned servers been removed from the settings of every environment?