Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(chart): stop the kubelet restarting the pod during boot

Yudhi Armyndharis67c1670f98f6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc3277aea..f2f626469 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- The chart's optional ServiceMonitor now scrapes one target per pod instead of two. Its selector matched only the shared selector labels, which both the ClusterIP and the headless Service carry, so Prometheus discovered a target through each and produced two sets of series distinguished only by the `service` label — enough to double-count any naive aggregation. The headless Service also publishes not-ready addresses, so it kept a target pointed at a pod whose port is still closed during boot and reported it as down. The ServiceMonitor and the ClusterIP Service now share a `openwa.io/scrape-target` label that the headless Service does not carry. After upgrading, series previously collected through the headless target stop appearing: check any dashboard or alerting rule that matches on the `service` label, which now always resolves to the ClusterIP Service.
+- The Helm chart no longer restarts the pod while it is still starting. The container binds its port only after every bootstrap hook has finished, so during boot the endpoint is closed rather than unhealthy and each liveness probe is a connection refusal; with no startup probe the liveness settings governed that window and allowed 50 seconds before the kubelet killed the container. This is not limited to deployments using session auto-start: the database connect retry alone is up to 10 attempts three seconds apart, so a database that is slow to accept connections can consume 30 of those 50 seconds on a stock install. A startup probe now allows 300 seconds (a 5-second period, 60 failures) and fires immediately, so a fast boot is recognised in about five seconds rather than after a fixed delay — the pod becomes live sooner than before, not later. A boot that is genuinely unbounded is not made safe by any fixed budget.
- A participant id carrying a recognised domain but a nonsense user-part — `NOT A [email protected]`, `@c.us` — is now rejected with `400` like any other malformed id. The earlier check tested only the domain, so these still reached WhatsApp Web and produced the same undiagnosable `500` the check was added to prevent. The same rule now backs the `mentions` validator, which had the identical gap, and it covers the two membership-request routes, which take the same ids and were missed the first time. A bare phone number is also qualified before it reaches the Baileys socket; previously it went out without a domain, which WhatsApp does not read as an id at all, so the write silently did nothing. Fixes #1220.
- Messages that existed before the full-text index was created are indexed on the next boot instead of being permanently unsearchable, and ordinary edits and deletes on them work again. The boot-time backfill was gated on the index being empty, but `messages_fts` is an FTS5 external-content table whose `count(*)` returns the row count of `messages`, so the condition could never hold and the backfill never ran; until those rows are indexed the sync triggers issue delete commands for documents that were never added and SQLite rejects the whole statement. The guard is now a rowid-level completeness check, so it also repairs a partially populated index rather than only an empty one.
- A WhatsApp-level refusal of a group participant add, remove, promote or demote on the Baileys engine is now reported as `403` instead of propagating as an unhandled error. Participant refusals normally arrive one per participant and were already mapped; a refusal of the request itself arrives through the other channel, and this was the only write in the Baileys group adapter that did not map it. A dropped connection or a timeout is still reported as itself rather than as a permissions problem. Refs #1220.
diff --git a/charts/openwa/templates/statefulset.yaml b/charts/openwa/templates/statefulset.yaml
index 922bddf19..75a85b831 100644
--- a/charts/openwa/templates/statefulset.yaml
+++ b/charts/openwa/templates/statefulset.yaml
@@ -35,6 +35,31 @@ spec:
name: {{ include "openwa.fullname" . }}
- secretRef:
name: {{ include "openwa.secretName" . }}
+ # The port is bound only after Nest has run every bootstrap hook — migrations, the database
+ # connect retry (up to 10 attempts, 3s apart), plugin load and the backfills — so during
+ # boot the endpoint is not unhealthy, it is closed, and every probe is a connection
+ # refusal. Without a startupProbe the liveness block below governs that window and allows
+ # 30s + 10s x (3-1) = 50s before the kubelet restarts the container, which the connect
+ # retry alone can consume.
+ #
+ # Budget here is periodSeconds x failureThreshold = 5 x 60 = 300s. That converts "killed
+ # at 50s by default" into "killed at a budget we chose" — a large improvement, and not a
+ # guarantee for a boot that is genuinely unbounded.
+ #
+ # initialDelaySeconds is deliberately left at its default of 0: the first probe fires
+ # immediately, so a fast boot is recognised in ~5s instead of waiting out a fixed delay.
+ # The pod therefore becomes live SOONER than it does today, not later.
+ #
+ # Kubernetes suspends the liveness and readiness probes until a startupProbe succeeds, so
+ # the values below keep their meaning for steady state and stop governing boot. (That
+ # suspension is documented kubelet behaviour, not something this chart's tests observe —
+ # rendering a manifest cannot demonstrate a runtime scheduling rule.)
+ startupProbe:
+ httpGet:
+ path: /api/health/live
+ port: http
+ periodSeconds: 5
+ failureThreshold: 60
livenessProbe:
httpGet:
path: /api/health/live