Fix runner hanging
This change allows `run_example` script to stop server even if client returned an error (adds an `exit-trap`).
Fixes
@@ -71,14 +71,15 @@ if [[ "${server}" != "none" ]]; then
"${SCRIPTS_DIR}/build_server" -s "${server}"
"${SCRIPTS_DIR}/run_server" -s "${server}" -l "${language}" -e "${EXAMPLE}" &
readonly SERVER_PID=$!
+
+ function stop_server {
+ kill -s SIGTERM "${SERVER_PID}"
+ }
+ trap stop_server EXIT
+
sleep 3 # Wait for the application to start.
fi
# Run the application client.
readonly CLIENT_ARGS=("${@}") # Choose client args provided after '--'.
"./bazel-client-bin/examples/${EXAMPLE}/client/client" "${CLIENT_ARGS[@]}"
-
-# TODO: Ensure that background processes are killed with something like `trap cleanup_fn EXIT`.
-if [[ "${server}" != "none" ]]; then
- kill -s SIGTERM "${SERVER_PID}"
-fi
