Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kafka/kafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function wait_for_zookeeper() {
function wait_for_kafka() {
for i in {1..20}; do
local broker_list=$(get_broker_list || true)
if [[ "${broker_list}" == *" ${BROKER_ID},"* ]]; then
if echo "${broker_list}" | grep -q "${BROKER_ID}"; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The current grep command is too broad and can lead to false positives due to partial string matching. For instance, if BROKER_ID is 1, this check would incorrectly succeed if a broker with ID 10 is registered.

To ensure only the exact broker ID is matched, please use the -w flag with grep to perform a whole-word search. This will correctly identify the broker ID while ignoring partial matches.

Suggested change
if echo "${broker_list}" | grep -q "${BROKER_ID}"; then
if echo "${broker_list}" | grep -qw "${BROKER_ID}"; then

return 0
else
echo "Kafka broker ${BROKER_ID} is not registered yet, retry ${i}..."
Expand Down