Skip to content

Commit eca9f99

Browse files
committed
Ensure the port isn't open before our git daemon
If a previous run of the git daemon still has port 9418 open, then we might think we successfully ran `git daemon`, when instead our asynchronous command could be failing to bind the port and quitting immediately. (The use of `set -e` would not mitigate this, since the `git daemon ... &` command would have successfully forked off the asynchronous subprocess.) One way that could happen, at least in principle, is if the `EXIT` trap from a previous run did not cause the `git-daemon` process to terminate. That could happen either due to: - The `EXIT` trap somehow not running. - The child `git-daemon` process not being caused to terminate when its parent `git` process terminates. They are actually separate processes: Running a `git daemon ...` command creates a `git` process, which then creates a `git-daemon` subprocess (where `git-daemon` is in the `git-core` directory `git --exec-path` gives). The parent `git` process forks before exec-ing the child `git-daemon` process. So they have separate PIDs. The PID from `$!` belongs to the parent `git` process. However, both processes are usually terminated, at least in simplified local experiments. This change aims to detect such conditions. (It might be worth keeping even if that kind of problem is not currently happening.)
1 parent 39a1cc7 commit eca9f99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tests/helpers.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ function small-repo-in-sandbox() {
6060
}
6161

6262
function launch-git-daemon() {
63+
local port=9418
64+
if nc -z localhost "$port"; then
65+
echo "Port $port should not have been open before this test's run of the git daemon!" >&2
66+
return 1
67+
fi
6368
git -c uploadpack.allowrefinwant daemon --verbose --base-path=. --export-all --user-path &>/dev/null &
6469
daemon_pid=$!
65-
while ! nc -z localhost 9418; do
70+
while ! nc -z localhost "$port"; do
6671
sleep 0.1
6772
done
6873
trap 'kill $daemon_pid' EXIT

0 commit comments

Comments
 (0)