From 159c87c0e69333aa78f2bc135b70e9ffbd5ff5a4 Mon Sep 17 00:00:00 2001 From: Edouard COMTET Date: Mon, 17 Aug 2026 10:53:53 +0200 Subject: [PATCH] [bitnami/mongodb, bitnami/mongodb-sharded] Fix secondary voting-rights check always returning true (#96305) mongodb_secondary_node_has_voting_rights(), introduced in #95156, greps the mongosh output for "true". mongosh always prints a connection banner holding "directConnection=true" on stdout, so the grep matches unconditionally and the function can never return false. mongodb_configure_secondary() therefore always takes the "Node already has voting rights" branch and the grant is never executed: secondaries are added with votes:0/priority:0 by rs.add() and stay there permanently, so only the node that ran rs.initiate() ends up holding a vote. Reproduced with mongosh 2.9.2, the version shipped in the 8.3 images: $ mongosh --host --port 27017 admin 2>/dev/null <<< 'print("x")' Current Mongosh Log ID: ... Connecting to: mongodb://:27017/admin?directConnection=true&appName=mongosh+2.9.2 Print an explicit HAS_VOTES_YES/HAS_VOTES_NO sentinel and match on that. The sentinel is concatenated at runtime so the positive value never appears verbatim in the script sent to mongosh. Also use .some() rather than .filter().length === 1. Verified on a 9-member sharded replica set: before the fix, a new secondary joining with a free voter slot stayed at votes:0 (9 members / 6 voters); after the fix it is granted votes:1/priority:1 (9 members / 7 voters). Signed-off-by: Edouard COMTET --- .../8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh | 7 +++++-- .../8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bitnami/mongodb-sharded/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh b/bitnami/mongodb-sharded/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh index 8959984f34cd..72c0820e6fa2 100644 --- a/bitnami/mongodb-sharded/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh +++ b/bitnami/mongodb-sharded/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh @@ -957,14 +957,17 @@ mongodb_secondary_node_has_voting_rights() { local result debug "Checking voting rights of the node" + # mongosh prints a connection banner containing 'directConnection=true', so a + # plain 'true' match always succeeds. Match an explicit sentinel instead, built + # at runtime so the positive value never appears verbatim in the sent script. result=$( mongodb_execute_print_output "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" "admin" "$MONGODB_INITIAL_PRIMARY_HOST" "$MONGODB_INITIAL_PRIMARY_PORT_NUMBER" < m.host === '$node:$port' && m.votes > 0 && m.priority > 0).length === 1 +print("HAS_VOTES_" + (rs.conf().members.some(m => m.host === '$node:$port' && m.votes > 0 && m.priority > 0) ? "YES" : "NO")) EOF ) debug "$result" - grep -q "true" <<<"$result" + grep -q "HAS_VOTES_YES" <<<"$result" } ######################## diff --git a/bitnami/mongodb/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh b/bitnami/mongodb/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh index 8959984f34cd..72c0820e6fa2 100644 --- a/bitnami/mongodb/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh +++ b/bitnami/mongodb/8.3/debian-12/rootfs/opt/bitnami/scripts/libmongodb.sh @@ -957,14 +957,17 @@ mongodb_secondary_node_has_voting_rights() { local result debug "Checking voting rights of the node" + # mongosh prints a connection banner containing 'directConnection=true', so a + # plain 'true' match always succeeds. Match an explicit sentinel instead, built + # at runtime so the positive value never appears verbatim in the sent script. result=$( mongodb_execute_print_output "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" "admin" "$MONGODB_INITIAL_PRIMARY_HOST" "$MONGODB_INITIAL_PRIMARY_PORT_NUMBER" < m.host === '$node:$port' && m.votes > 0 && m.priority > 0).length === 1 +print("HAS_VOTES_" + (rs.conf().members.some(m => m.host === '$node:$port' && m.votes > 0 && m.priority > 0) ? "YES" : "NO")) EOF ) debug "$result" - grep -q "true" <<<"$result" + grep -q "HAS_VOTES_YES" <<<"$result" } ########################