Skip to content

Commit ee01f55

Browse files
authored
Add configurable timeout to netcat calls with 10s default (#78370)
Add configurable timeout to netcat calls with 10s default Without any timeout, netcat can get stuck forever (until Kubernetes kills unhealthy Pod) when configured address and port combination is wrong, or the connection gets stuck. For example `nc -z bitnami.com 12345` doesn't seem to ever finish. In the case when an attempt gets stuck, the timeout will allow further attempts to be performed, instead of waiting until Pod is killed. Signed-off-by: Mateusz Mikuła <oss@mateuszmikula.dev>
1 parent 6bc270f commit ee01f55

File tree

11 files changed

+48
-37
lines changed

11 files changed

+48
-37
lines changed

bitnami/ksql/7.8/debian-12/rootfs/opt/bitnami/scripts/ksql-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ksql_env_vars=(
3030
KSQL_SSL_TRUSTSTORE_PASSWORD
3131
KSQL_CLIENT_AUTHENTICATION
3232
KSQL_BOOTSTRAP_SERVERS
33+
KSQL_CONNECTION_ATTEMPT_TIMEOUT
3334
)
3435
for env_var in "${ksql_env_vars[@]}"; do
3536
file_env_var="${env_var}_FILE"
@@ -67,5 +68,6 @@ export KSQL_SSL_KEYSTORE_PASSWORD="${KSQL_SSL_KEYSTORE_PASSWORD:-}"
6768
export KSQL_SSL_TRUSTSTORE_PASSWORD="${KSQL_SSL_TRUSTSTORE_PASSWORD:-}"
6869
export KSQL_CLIENT_AUTHENTICATION="${KSQL_CLIENT_AUTHENTICATION:-}"
6970
export KSQL_BOOTSTRAP_SERVERS="${KSQL_BOOTSTRAP_SERVERS:-}"
71+
export KSQL_CONNECTION_ATTEMPT_TIMEOUT="${KSQL_CONNECTION_ATTEMPT_TIMEOUT:10}"
7072

7173
# Custom environment variables may be defined below

bitnami/ksql/7.8/debian-12/rootfs/opt/bitnami/scripts/libksql.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ ksql_wait_for_kafka_brokers() {
181181
if [[ "$b" =~ [_a-zA-Z]*://(.*):([0-9]*) ]]; then
182182
host="${BASH_REMATCH[1]}"
183183
port="${BASH_REMATCH[2]}"
184-
if ! retry_while "debug_execute nc -z ${host} ${port}" 10 10; then
184+
if ! retry_while "debug_execute nc -w $KSQL_CONNECTION_ATTEMPT_TIMEOUT -z ${host} ${port}" 10 10; then
185185
error "Failed to connect to the broker at $host:$port"
186186
return 1
187187
fi

bitnami/ksql/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,15 @@ docker build -t bitnami/APP:latest .
6363

6464
### Customizable environment variables
6565

66-
| Name | Description | Default Value |
67-
|--------------------------------|-----------------------------------------------------------------------------------------------|--------------------------|
68-
| `KSQL_MOUNTED_CONF_DIR` | Directory for including custom configuration files (that override the default generated ones) | `${KSQL_VOLUME_DIR}/etc` |
69-
| `KSQL_LISTENERS` | Comma-separated list of listeners that listen for API requests over either HTTP or HTTPS. | `nil` |
70-
| `KSQL_SSL_KEYSTORE_PASSWORD` | Password to access the SSL keystore. | `nil` |
71-
| `KSQL_SSL_TRUSTSTORE_PASSWORD` | Password to access the SSL truststore. | `nil` |
72-
| `KSQL_CLIENT_AUTHENTICATION` | Client authentication configuration. Valid options: none, requested, over required. | `nil` |
73-
| `KSQL_BOOTSTRAP_SERVERS` | The set of Kafka brokers to bootstrap Kafka cluster information from. | `nil` |
66+
| Name | Description | Default Value |
67+
|-----------------------------------|-----------------------------------------------------------------------------------------------|--------------------------|
68+
| `KSQL_MOUNTED_CONF_DIR` | Directory for including custom configuration files (that override the default generated ones) | `${KSQL_VOLUME_DIR}/etc` |
69+
| `KSQL_LISTENERS` | Comma-separated list of listeners that listen for API requests over either HTTP or HTTPS. | `nil` |
70+
| `KSQL_SSL_KEYSTORE_PASSWORD` | Password to access the SSL keystore. | `nil` |
71+
| `KSQL_SSL_TRUSTSTORE_PASSWORD` | Password to access the SSL truststore. | `nil` |
72+
| `KSQL_CLIENT_AUTHENTICATION` | Client authentication configuration. Valid options: none, requested, over required. | `nil` |
73+
| `KSQL_BOOTSTRAP_SERVERS` | The set of Kafka brokers to bootstrap Kafka cluster information from. | `nil` |
74+
| `KSQL_CONNECTION_ATTEMPT_TIMEOUT` | Timeout in seconds for connection attempts. | `10` |
7475

7576
### Read-only environment variables
7677

bitnami/schema-registry/7.7/debian-12/rootfs/opt/bitnami/scripts/libschemaregistry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ schema_registry_for_kafka_brokers() {
254254
if [[ "$b" =~ [_a-zA-Z]*://(.*):([0-9]*) ]]; then
255255
host="${BASH_REMATCH[1]}"
256256
port="${BASH_REMATCH[2]}"
257-
if ! retry_while "debug_execute nc -z ${host} ${port}" 10 10; then
257+
if ! retry_while "debug_execute nc -w $SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT -z ${host} ${port}" 10 10; then
258258
error "Failed to connect to the broker at $host:$port"
259259
return 1
260260
fi

bitnami/schema-registry/7.7/debian-12/rootfs/opt/bitnami/scripts/schema-registry-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ schema_registry_env_vars=(
4040
SCHEMA_REGISTRY_CLIENT_AUTHENTICATION
4141
SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL
4242
SCHEMA_REGISTRY_DEBUG
43+
SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT
4344
)
4445
for env_var in "${schema_registry_env_vars[@]}"; do
4546
file_env_var="${env_var}_FILE"
@@ -87,5 +88,6 @@ export SCHEMA_REGISTRY_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM="${SCHEMA_REGISTRY_
8788
export SCHEMA_REGISTRY_CLIENT_AUTHENTICATION="${SCHEMA_REGISTRY_CLIENT_AUTHENTICATION:-}"
8889
export SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL="${SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL:-}"
8990
export SCHEMA_REGISTRY_DEBUG="${SCHEMA_REGISTRY_DEBUG:-}"
91+
export SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT="${SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT:10}"
9092

9193
# Custom environment variables may be defined below

bitnami/schema-registry/7.8/debian-12/rootfs/opt/bitnami/scripts/libschemaregistry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ schema_registry_for_kafka_brokers() {
254254
if [[ "$b" =~ [_a-zA-Z]*://(.*):([0-9]*) ]]; then
255255
host="${BASH_REMATCH[1]}"
256256
port="${BASH_REMATCH[2]}"
257-
if ! retry_while "debug_execute nc -z ${host} ${port}" 10 10; then
257+
if ! retry_while "debug_execute nc -w $SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT -z ${host} ${port}" 10 10; then
258258
error "Failed to connect to the broker at $host:$port"
259259
return 1
260260
fi

bitnami/schema-registry/7.8/debian-12/rootfs/opt/bitnami/scripts/schema-registry-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ schema_registry_env_vars=(
4040
SCHEMA_REGISTRY_CLIENT_AUTHENTICATION
4141
SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL
4242
SCHEMA_REGISTRY_DEBUG
43+
SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT
4344
)
4445
for env_var in "${schema_registry_env_vars[@]}"; do
4546
file_env_var="${env_var}_FILE"
@@ -87,5 +88,6 @@ export SCHEMA_REGISTRY_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM="${SCHEMA_REGISTRY_
8788
export SCHEMA_REGISTRY_CLIENT_AUTHENTICATION="${SCHEMA_REGISTRY_CLIENT_AUTHENTICATION:-}"
8889
export SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL="${SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL:-}"
8990
export SCHEMA_REGISTRY_DEBUG="${SCHEMA_REGISTRY_DEBUG:-}"
91+
export SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT="${SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT:10}"
9092

9193
# Custom environment variables may be defined below

bitnami/schema-registry/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ docker build -t bitnami/APP:latest .
8484
| `SCHEMA_REGISTRY_CLIENT_AUTHENTICATION` | Client authentication configuration. Valid options: none, requested, over required. | `nil` |
8585
| `SCHEMA_REGISTRY_AVRO_COMPATIBILY_LEVEL` | The Avro compatibility type. Valid options: none, backward, backward_transitive, forward, forward_transitive, full, or full_transitive | `nil` |
8686
| `SCHEMA_REGISTRY_DEBUG` | Enable Schema Registry debug logs. Valid options: true or false | `nil` |
87+
| `SCHEMA_REGISTRY_CONNECTION_ATTEMPT_TIMEOUT` | Timeout for connection attempts in seconds. | `10` |
8788

8889
#### Read-only environment variables
8990

bitnami/solr/9/debian-12/rootfs/opt/bitnami/scripts/libsolr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ solr_wait_for_zookeeper() {
162162
host="${BASH_REMATCH[1]}"
163163
port="${BASH_REMATCH[2]}"
164164
debug "Trying: $host:$port"
165-
if ! retry_while "debug_execute nc -z ${host} ${port}" "$SOLR_ZK_MAX_RETRIES" "$SOLR_ZK_SLEEP_TIME"; then
165+
if ! retry_while "debug_execute nc -w $SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT -z ${host} ${port}" "$SOLR_ZK_MAX_RETRIES" "$SOLR_ZK_SLEEP_TIME"; then
166166
error "Failed to connect to the zookeeper node at ${host}:${port}"
167167
return 1
168168
fi

bitnami/solr/9/debian-12/rootfs/opt/bitnami/scripts/solr-env.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ solr_env_vars=(
4848
SOLR_ZK_CHROOT
4949
SOLR_ZK_HOSTS
5050
SOLR_COLLECTION
51+
SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT
5152
)
5253
for env_var in "${solr_env_vars[@]}"; do
5354
file_env_var="${env_var}_FILE"
@@ -109,5 +110,6 @@ export SOLR_ZK_MAX_RETRIES="${SOLR_ZK_MAX_RETRIES:-5}"
109110
export SOLR_ZK_SLEEP_TIME="${SOLR_ZK_SLEEP_TIME:-5}"
110111
export SOLR_ZK_CHROOT="${SOLR_ZK_CHROOT:-/solr}"
111112
export SOLR_ZK_HOSTS="${SOLR_ZK_HOSTS:-}"
113+
export SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT="${SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT:-10}"
112114

113115
# Custom environment variables may be defined below

0 commit comments

Comments
 (0)