Skip to content

Commit

Permalink
fix: address already in use (#845)
Browse files Browse the repository at this point in the history
* fix: address already in use

* fix: always sleep
  • Loading branch information
shumkov authored Jul 24, 2024
1 parent 6933cae commit 13492fd
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions DOCKER/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#!/bin/bash
set -e


# TODO: Workaround for busy port problem happening with docker restart policy
# we are trying to start a new container but previous process still not release
# the port.

# As a workaround we are sleeping for 10 seconds after the tenderdash process
# exits with non-zero exit code.
#
# Must be fix with graceful shutdown of tenderdash process.

got_signal=false

# Function to handle signals and forward them to the tenderdash process
# shellcheck disable=SC2317
_forward_signal() {
echo "Caught signal! Forwarding to tenderdash process."
got_signal=true
kill -s "$1" "$child"
}

# Trap signals and forward them to the tenderdash process
trap '_forward_signal TERM' SIGTERM
trap '_forward_signal INT' SIGINT
trap '_forward_signal HUP' SIGHUP
trap '_forward_signal QUIT' SIGQUIT

if [ ! -d "$TMHOME/config" ]; then
echo "Running tenderdash init to create a single node (default) configuration for docker run."
Expand All @@ -26,4 +51,15 @@ if [ ! -d "$TMHOME/config" ]; then
mv "$TMHOME/config/genesis.json.new" "$TMHOME/config/genesis.json"
fi

exec tenderdash "$@"
# Start tenderdash in the background
tenderdash "$@" &
child=$!
wait "$child"
exit_code=$?

if [ $got_signal == false ] && [ $exit_code -ne 0 ] && [ "$1" == "start" ]; then
echo "Sleeping for 10 seconds as workaround for the busy port problem. See entrypoint code for details."
sleep 10
fi

exit $exit_code

0 comments on commit 13492fd

Please sign in to comment.