소스 검색

SubprocessClient: timeout after 60s of inactivity when closing channel (#1552)

This will prevent any indefinite hangs, and instead turn them into
exceptions. Hopefully that will help drill down why this is happening
for some users.
Jelmer Vernooij 2 주 전
부모
커밋
a01b7caa7b
2개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 1
      NEWS
  2. 9 2
      dulwich/client.py

+ 5 - 1
NEWS

@@ -15,7 +15,11 @@
 
  * Bump PyO3 to 0.25. (Jelmer Vernooij)
 
- * Fix typing for ``dulwich.client`` methods that take repositories.
+ * In ``SubprocessClient`` time out after 60 seconds
+   when the subprocess hasn't terminated when closing
+   the channel. (Jelmer Vernooij)
+
+* Fix typing for ``dulwich.client`` methods that take repositories.
    (Jelmer Vernooij, #1521)
 
 0.22.8	2025-03-02

+ 9 - 2
dulwich/client.py

@@ -1661,12 +1661,19 @@ class SubprocessWrapper:
         else:
             return _fileno_can_read(self.proc.stdout.fileno())
 
-    def close(self) -> None:
+    def close(self, timeout: Optional[int] = 60) -> None:
         self.proc.stdin.close()
         self.proc.stdout.close()
         if self.proc.stderr:
             self.proc.stderr.close()
-        self.proc.wait()
+        try:
+            self.proc.wait(timeout=timeout)
+        except subprocess.TimeoutExpired as e:
+            self.proc.kill()
+            self.proc.wait()
+            raise GitProtocolError(
+                f"Git subprocess did not terminate within {timeout} seconds; killed it."
+            ) from e
 
 
 def find_git_command() -> list[str]: