Explorar o código

SubprocessClient: timeout after 60s of inactivity when closing channel

Jelmer Vernooij hai 2 semanas
pai
achega
e4e1045687
Modificáronse 2 ficheiros con 13 adicións e 2 borrados
  1. 4 0
      NEWS
  2. 9 2
      dulwich/client.py

+ 4 - 0
NEWS

@@ -15,6 +15,10 @@
 
  * Bump PyO3 to 0.25. (Jelmer Vernooij)
 
+ * In ``SubprocessClient`` time out after 60 seconds
+   when the subprocess hasn't terminated when closing
+   the channel. (Jelmer Vernooij)
+
 0.22.8	2025-03-02
 
  * Allow passing in plain strings to ``dulwich.porcelain.tag_create``

+ 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]: