From 48ab309698a3acacf8b16063e2d9b89097196585 Mon Sep 17 00:00:00 2001 From: samuel Date: Sun, 30 Apr 2023 23:31:43 +0200 Subject: [PATCH] [Fix] Add a timeout for each inotifywait to prevent eventual locks --- src/deployer.sh | 3 ++- src/pipeline.sh | 3 ++- src/runner.sh | 6 ++++-- tests/deployer.bats | 3 ++- tests/runner.bats | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/deployer.sh b/src/deployer.sh index eb62cc8..19c5500 100755 --- a/src/deployer.sh +++ b/src/deployer.sh @@ -395,7 +395,8 @@ main() ( # Set right access in background after nc listen. ( - inotifywait --event create "$(dirname "${deployer_sock}")" --quiet --quiet + inotifywait --timeout 1 --quiet --quiet \ + --event create "$(dirname "${deployer_sock}")" || true chmod 775 "${deployer_sock}" chgrp "${runner_deployer_groupname}" "${deployer_sock}" ) & diff --git a/src/pipeline.sh b/src/pipeline.sh index 4bde8fa..f62d65e 100755 --- a/src/pipeline.sh +++ b/src/pipeline.sh @@ -240,7 +240,8 @@ main() ( # Send request to runner. mkdir "${rd_pipeline_sock_dir}" ( - inotifywait --quiet --quiet --event create "${rd_pipeline_sock_dir}" + inotifywait --timeout 1 --quiet --quiet \ + --event create "${rd_pipeline_sock_dir}" || true chmod 775 "${rd_pipeline_sock}" chgrp "${git_runner_groupname}" "${rd_pipeline_sock}" echo "${runner_request}" | ncat --unixsock "${runner_sock}" diff --git a/src/runner.sh b/src/runner.sh index e5129e9..21d93ea 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -263,7 +263,8 @@ process_request() ( --arg v "$(make version)" \ '{"response_sock":$s,"pkg_name":$n,"pkg_version":$v}')" ( - inotifywait --event create "${repo_clone}" 1>/dev/null 2>/dev/null + inotifywait --timeout 1 --quiet --quiet \ + --event create "${repo_clone}" || true chmod 775 "${repo_clone}/runner.sock" chgrp "${runner_deployer_groupname}" "${repo_clone}/runner.sock" echo "${deployer_request}" | ncat --unixsock "${deployer_sock}" @@ -489,7 +490,8 @@ main() ( # Set right access in background after nc listen. ( - inotifywait --event create "$(dirname "${runner_sock}")" --quiet --quiet + inotifywait --timeout 1 --quiet --quiet \ + --event create "$(dirname "${runner_sock}")" || true chmod 775 "${runner_sock}" chgrp "${git_runner_groupname}" "${runner_sock}" ) & diff --git a/tests/deployer.bats b/tests/deployer.bats index d7d2259..55e028b 100644 --- a/tests/deployer.bats +++ b/tests/deployer.bats @@ -45,7 +45,8 @@ send_request() ( "${deployer_bin}" --conf="${conf_file}" --errs="${errs_file}" \ --daemon --once --verbose || return $? ( - inotifywait --event create --quiet --quiet "${response_sock_dir}" + inotifywait --timeout 1 --quiet --quiet \ + --event create "${response_sock_dir}" || true echo "${request}" | ncat --unixsock "${deployer_sock}" ) & return "$(ncat --listen --unixsock "${response_sock}" | jq .code)" diff --git a/tests/runner.bats b/tests/runner.bats index 42a79a0..1b02d2b 100644 --- a/tests/runner.bats +++ b/tests/runner.bats @@ -53,7 +53,8 @@ send_request() ( return "${code}" fi ( - inotifywait --quiet --quiet --event create "${response_sock_dir}" + inotifywait --timeout 1 --quiet --quiet \ + --event create "${response_sock_dir}" >&3 echo "${request}" | ncat --unixsock "${runner_sock}" ) & echo "done" | ncat --unixsock "${deployer_sock}"