-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(docker): prevent zombie processes #5878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+24
−9
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13b4ff4
fix: health check script
vyavdoshenko 7381c65
fix: health check script and docker files
vyavdoshenko 185f447
fix: review comments
vyavdoshenko 4ea5bcd
fix: healthcheck script
vyavdoshenko aba151d
fix: healthcheck script
vyavdoshenko f62f725
fix: healthcheck script
vyavdoshenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
#!/bin/sh | ||
|
||
# Cleanup function to prevent zombie processes (issue #5844) | ||
# This is critical when dragonfly runs as PID 1 without an init system | ||
cleanup() { | ||
# Wait for all background/child processes to finish | ||
wait 2>/dev/null || true | ||
} | ||
|
||
# Set trap to ensure cleanup runs on exit, regardless of how the script exits | ||
trap cleanup EXIT | ||
|
||
HOST="localhost" | ||
PORT=$HEALTHCHECK_PORT | ||
|
||
|
||
if [ -z "$HEALTHCHECK_PORT" ]; then | ||
# try unpriveleged version first. This should cover cases when the container is running | ||
# without root, for example: | ||
# docker run --group-add 999 --cap-drop=ALL --user 999 docker.dragonflydb.io/dragonflydb/dragonfly | ||
DF_NET=$(netstat -tlnp | grep "1/dragonfly") | ||
DF_NET=$(netstat -tlnp | grep "/dragonfly") | ||
if [ -z "$DF_NET" ]; then | ||
# if we failed, then lets try the priveleged version. is triggerred by the regular command: | ||
# docker run docker.dragonflydb.io/dragonflydb/dragonfly | ||
DF_NET=$(su dfly -c "netstat -tlnp" | grep "1/dragonfly") | ||
DF_NET=$(su dfly -c "netstat -tlnp" | grep "/dragonfly") | ||
fi | ||
|
||
# check all the TCP ports, and fetch the port. | ||
# For cases when dragonfly opens multiple ports, we filter with tail to choose one of them. | ||
PORT=$(echo $DF_NET | grep -oE ':[0-9]+' | cut -c2- | tail -n 1) | ||
fi | ||
|
||
_healthcheck="nc -q1 $HOST $PORT" | ||
# Use redis-cli instead of nc for better reliability | ||
# and to properly check loading state (issue #5863) | ||
REDIS_CLI="redis-cli -h $HOST -p $PORT" | ||
|
||
echo PING | ${_healthcheck} | ||
# Step 1: Basic PING check | ||
if ! timeout 3 $REDIS_CLI PING 2>/dev/null | grep -q "PONG"; then | ||
exit 1 | ||
fi | ||
|
||
# Step 2: Check if server is in LOADING state | ||
# During snapshot loading, the server responds to PING but is not ready for traffic | ||
# Note: 'loading' field is in PERSISTENCE section | ||
INFO_OUTPUT=$(timeout 3 $REDIS_CLI INFO PERSISTENCE 2>/dev/null) | ||
|
||
|
||
# Server is ready when loading:0 | ||
if echo "$INFO_OUTPUT" | grep -q "^loading:0"; then | ||
exit 0 | ||
fi | ||
|
||
exit $? | ||
# If loading:1 or can't determine state, fail to be safe | ||
exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used redis-cli in the past but had problems with that - please check the history and see why.
I prefer reverting to
nc
if this is not crucial for the fixes references in the PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.