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>
This commit is contained in:
Mateusz Mikuła
2025-03-13 17:48:09 +01:00
committed by GitHub
parent 6bc270fe9c
commit ee01f555fa
11 changed files with 48 additions and 37 deletions

View File

@@ -162,7 +162,7 @@ solr_wait_for_zookeeper() {
host="${BASH_REMATCH[1]}"
port="${BASH_REMATCH[2]}"
debug "Trying: $host:$port"
if ! retry_while "debug_execute nc -z ${host} ${port}" "$SOLR_ZK_MAX_RETRIES" "$SOLR_ZK_SLEEP_TIME"; then
if ! retry_while "debug_execute nc -w $SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT -z ${host} ${port}" "$SOLR_ZK_MAX_RETRIES" "$SOLR_ZK_SLEEP_TIME"; then
error "Failed to connect to the zookeeper node at ${host}:${port}"
return 1
fi

View File

@@ -48,6 +48,7 @@ solr_env_vars=(
SOLR_ZK_CHROOT
SOLR_ZK_HOSTS
SOLR_COLLECTION
SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT
)
for env_var in "${solr_env_vars[@]}"; do
file_env_var="${env_var}_FILE"
@@ -109,5 +110,6 @@ export SOLR_ZK_MAX_RETRIES="${SOLR_ZK_MAX_RETRIES:-5}"
export SOLR_ZK_SLEEP_TIME="${SOLR_ZK_SLEEP_TIME:-5}"
export SOLR_ZK_CHROOT="${SOLR_ZK_CHROOT:-/solr}"
export SOLR_ZK_HOSTS="${SOLR_ZK_HOSTS:-}"
export SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT="${SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT:-10}"
# Custom environment variables may be defined below

View File

@@ -150,31 +150,32 @@ docker-compose up -d
#### Customizable environment variables
| Name | Description | Default Value |
|---------------------------------|-------------------------------------------------------------------------------|----------------------------------------------------|
| `SOLR_ENABLE_CLOUD_MODE` | Starts solr in cloud mode | `no` |
| `SOLR_NUMBER_OF_NODES` | Number of nodes of the solr cloud cluster | `1` |
| `SOLR_HOST` | Solr Host name | `nil` |
| `SOLR_JETTY_HOST` | Configuration to listen on a specific IP address or host name | `0.0.0.0` |
| `SOLR_HEAP` | Solr Heap | `nil` |
| `SOLR_SECURITY_MANAGER_ENABLED` | Solr Java security manager | `false` |
| `SOLR_JAVA_MEM` | Solr JVM memory | `-Xms512m -Xmx512m` |
| `SOLR_PORT_NUMBER` | Solr port number | `8983` |
| `SOLR_CORES` | Solr CORE name | `nil` |
| `SOLR_COLLECTION` | Solr COLLECTION name | `nil` |
| `SOLR_COLLECTION_REPLICAS` | Solar collection replicas | `1` |
| `SOLR_COLLECTION_SHARDS` | Solar collection shards | `1` |
| `SOLR_ENABLE_AUTHENTICATION` | Enables authentication | `no` |
| `SOLR_ADMIN_USERNAME` | Administrator Username | `admin` |
| `SOLR_ADMIN_PASSWORD` | Administrator password | `bitnami` |
| `SOLR_CLOUD_BOOTSTRAP` | Indicates if this node is the one that performs the boostraping | `no` |
| `SOLR_CORE_CONF_DIR` | Solar CORE configuration directory | `${SOLR_SERVER_DIR}/solr/configsets/_default/conf` |
| `SOLR_SSL_ENABLED` | Indicates if Solr starts with SSL enabled | `no` |
| `SOLR_SSL_CHECK_PEER_NAME` | Indicates if Solr should check the peer names | `false` |
| `SOLR_ZK_MAX_RETRIES` | Maximum retries when waiting for zookeeper configuration operations to finish | `5` |
| `SOLR_ZK_SLEEP_TIME` | Sleep time when waiting for zookeeper configuration operations to finish | `5` |
| `SOLR_ZK_CHROOT` | ZooKeeper ZNode chroot where to store solr data. Default: /solr | `/solr` |
| `SOLR_ZK_HOSTS` | ZooKeeper nodes (comma-separated list of `host:port`\) | `nil` |
| Name | Description | Default Value |
|--------------------------------------|-------------------------------------------------------------------------------|----------------------------------------------------|
| `SOLR_ENABLE_CLOUD_MODE` | Starts solr in cloud mode | `no` |
| `SOLR_NUMBER_OF_NODES` | Number of nodes of the solr cloud cluster | `1` |
| `SOLR_HOST` | Solr Host name | `nil` |
| `SOLR_JETTY_HOST` | Configuration to listen on a specific IP address or host name | `0.0.0.0` |
| `SOLR_HEAP` | Solr Heap | `nil` |
| `SOLR_SECURITY_MANAGER_ENABLED` | Solr Java security manager | `false` |
| `SOLR_JAVA_MEM` | Solr JVM memory | `-Xms512m -Xmx512m` |
| `SOLR_PORT_NUMBER` | Solr port number | `8983` |
| `SOLR_CORES` | Solr CORE name | `nil` |
| `SOLR_COLLECTION` | Solr COLLECTION name | `nil` |
| `SOLR_COLLECTION_REPLICAS` | Solar collection replicas | `1` |
| `SOLR_COLLECTION_SHARDS` | Solar collection shards | `1` |
| `SOLR_ENABLE_AUTHENTICATION` | Enables authentication | `no` |
| `SOLR_ADMIN_USERNAME` | Administrator Username | `admin` |
| `SOLR_ADMIN_PASSWORD` | Administrator password | `bitnami` |
| `SOLR_CLOUD_BOOTSTRAP` | Indicates if this node is the one that performs the boostraping | `no` |
| `SOLR_CORE_CONF_DIR` | Solar CORE configuration directory | `${SOLR_SERVER_DIR}/solr/configsets/_default/conf` |
| `SOLR_SSL_ENABLED` | Indicates if Solr starts with SSL enabled | `no` |
| `SOLR_SSL_CHECK_PEER_NAME` | Indicates if Solr should check the peer names | `false` |
| `SOLR_ZK_MAX_RETRIES` | Maximum retries when waiting for zookeeper configuration operations to finish | `5` |
| `SOLR_ZK_SLEEP_TIME` | Sleep time when waiting for zookeeper configuration operations to finish | `5` |
| `SOLR_ZK_CHROOT` | ZooKeeper ZNode chroot where to store solr data. Default: /solr | `/solr` |
| `SOLR_ZK_HOSTS` | ZooKeeper nodes (comma-separated list of `host:port`\) | `nil` |
| `SOLR_ZK_CONNECTION_ATTEMPT_TIMEOUT` | ZooKeeper connection attempt timeout in seconds | `10` |
#### Read-only environment variables