Skip to content

Commit 0b2751b

Browse files
committed
[bitnami/mongodb-sharded] fix(mongos): use exact match in liveness probe pgrep
The mongos liveness probe uses `pgrep mongos` to check if the mongos process is running. However, `pgrep` performs substring matching by default, so `pgrep mongos` also matches `mongosh` processes (since "mongos" is a substring of "mongosh"). This causes a critical failure mode during startup: when all MongoDB sharded StatefulSets start simultaneously, mongos may attempt to connect to configsvr before its replica set is fully initialized. The Bitnami entrypoint script runs `mongosh --host configsvr` to verify configsvr availability, but this call blocks indefinitely when configsvr's port is open but the replica set hasn't completed primary election or auth user creation. Since the `mongosh` call has no timeout, it hangs forever, and the actual `mongos` router process is never started. At this point, the liveness probe should detect that mongos is not running and restart the container. However, `pgrep mongos` matches the hung `mongosh` child process, so the liveness probe passes. The container remains stuck permanently: liveness passes (due to the substring match on mongosh), readiness fails (correctly, since mongos never started), and Kubernetes never restarts it. Meanwhile, shard data nodes complete their own init, stop mongod, and try to register with mongos. Since mongos never started, shards loop on "timeout reached before the port went into state inuse" and get killed by their own liveness probes, entering CrashLoopBackOff. The fix adds the `-x` flag to `pgrep`, which requires an exact match on the process name. With this change, `pgrep -x mongos` matches only the real `mongos` process and not `mongosh`, so if the entrypoint hangs, the liveness probe correctly fails and Kubernetes restarts the container. On retry, configsvr is typically ready, and startup succeeds. Signed-off-by: Jacques Maude <delthas@dille.cc>
1 parent 9782af9 commit 0b2751b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

bitnami/mongodb-sharded/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ maintainers:
3737
name: mongodb-sharded
3838
sources:
3939
- https://github.com/bitnami/charts/tree/main/bitnami/mongodb-sharded
40-
version: 9.4.13
40+
version: 9.4.14

bitnami/mongodb-sharded/templates/mongos/mongos-dep-sts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ spec:
208208
exec:
209209
command:
210210
- pgrep
211+
- -x
211212
- mongos
212213
{{- end }}
213214
{{- if .Values.mongos.customReadinessProbe }}

0 commit comments

Comments
 (0)