diff --git a/bot_bottle/git_gate.py b/bot_bottle/git_gate.py index 239499c..acbf4d4 100644 --- a/bot_bottle/git_gate.py +++ b/bot_bottle/git_gate.py @@ -43,10 +43,10 @@ from .manifest import ManifestBottle, ManifestGitEntry # Short network alias for git-gate inside the sidecar bundle. The # agent's `.gitconfig` insteadOf rewrites resolve through this name. GIT_GATE_HOSTNAME = "git-gate" -# Bound half-open git client sessions. If an agent/tool runner is -# interrupted during push, git daemon should reap the receive-pack -# child instead of keeping the gate wedged indefinitely. -GIT_GATE_DAEMON_TIMEOUT_SECS = 15 +# Shared timeout (seconds) for all git-gate subprocess and CGI calls: +# git daemon (--timeout/--init-timeout), the access-hook subprocess in +# git_http_backend, and the git http-backend CGI subprocess. +GIT_GATE_TIMEOUT_SECS = 15 @dataclass(frozen=True) @@ -217,8 +217,8 @@ def git_gate_render_entrypoint(upstreams: tuple[GitGateUpstream, ...]) -> str: "", "exec git daemon \\", " --reuseaddr \\", - f" --timeout={GIT_GATE_DAEMON_TIMEOUT_SECS} \\", - f" --init-timeout={GIT_GATE_DAEMON_TIMEOUT_SECS} \\", + f" --timeout={GIT_GATE_TIMEOUT_SECS} \\", + f" --init-timeout={GIT_GATE_TIMEOUT_SECS} \\", " --base-path=/git \\", " --export-all \\", " --enable=receive-pack \\", diff --git a/bot_bottle/git_http_backend.py b/bot_bottle/git_http_backend.py index add4b3b..1b45a38 100644 --- a/bot_bottle/git_http_backend.py +++ b/bot_bottle/git_http_backend.py @@ -16,7 +16,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from pathlib import Path from urllib.parse import urlsplit -from .git_gate import GIT_GATE_DAEMON_TIMEOUT_SECS +from .git_gate import GIT_GATE_TIMEOUT_SECS DEFAULT_PORT = 9420 @@ -49,7 +49,7 @@ class GitHttpHandler(BaseHTTPRequestHandler): [hook_path, "upload-pack", str(repo_dir), peer, peer], capture_output=True, check=False, - timeout=GIT_GATE_DAEMON_TIMEOUT_SECS, + timeout=GIT_GATE_TIMEOUT_SECS, ) if hook.returncode != 0: detail = (hook.stderr or hook.stdout).decode( @@ -113,7 +113,7 @@ class GitHttpHandler(BaseHTTPRequestHandler): env=env, capture_output=True, check=False, - timeout=GIT_GATE_DAEMON_TIMEOUT_SECS, + timeout=GIT_GATE_TIMEOUT_SECS, ) self._write_cgi_response(proc.stdout) diff --git a/tests/unit/test_git_http_backend.py b/tests/unit/test_git_http_backend.py index ef70628..c605eb0 100644 --- a/tests/unit/test_git_http_backend.py +++ b/tests/unit/test_git_http_backend.py @@ -9,7 +9,7 @@ import urllib.request from pathlib import Path from unittest import mock -from bot_bottle.git_gate import GIT_GATE_DAEMON_TIMEOUT_SECS +from bot_bottle.git_gate import GIT_GATE_TIMEOUT_SECS from bot_bottle.git_http_backend import GitHttpHandler, MAX_BODY_BYTES @@ -201,7 +201,7 @@ class TestGitHttpBackend(unittest.TestCase): for call in run.call_args_list: self.assertEqual( - GIT_GATE_DAEMON_TIMEOUT_SECS, + GIT_GATE_TIMEOUT_SECS, call.kwargs.get("timeout"), f"subprocess.run call missing timeout: {call}", )