سامانه صدور فاکتور و حسابداری
fix: drain pg_restore stderr asynchronously and remove partial files on interruption
davoodmehraban89 committed
Oct 14, 2026 at 22:32 UTC
bb33660c31dab517242cb87a31a18f0fc1c3347c
1 file changed
+7
-2
scripts/finora_local_backup.py
+7
-2
@@ -156,7 +156,7 @@ def backup(args: argparse.Namespace) -> Path:
156
print(f"Integrity manifest: {manifest}")
157
print("Copy BOTH files to separate offline storage. Perform a sandbox restore before trusting the backup.")
158
return final
159
- except Exception:
159
+ except BaseException:
160
for path in (partial, final, manifest_temp, manifest):
161
try:
162
path.unlink(missing_ok=True)
@@ -202,6 +202,11 @@ def decrypt_into_process(path: Path, identity: Path, age: str, command: list[str
202
consumer = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL,
203
stderr=subprocess.PIPE, env=env)
204
assert dec.stdout is not None and consumer.stdin is not None
205
+ consumer_errors: list[bytes] = []
206
+ consumer_err_thread = threading.Thread(
207
+ target=_read_stderr, args=(consumer, consumer_errors), daemon=True
208
+ )
209
+ consumer_err_thread.start()
210
broken = False
211
while chunk := dec.stdout.read(256 * 1024):
212
if not broken:
@@ -214,8 +219,8 @@ def decrypt_into_process(path: Path, identity: Path, age: str, command: list[str
219
consumer.stdin.close()
220
except BrokenPipeError:
221
pass
217
- consumer_stderr = consumer.stderr.read() if consumer.stderr else b""
222
consumer_rc = consumer.wait()
223
+ consumer_err_thread.join(timeout=5)
224
dec_rc = dec.wait()
225
thread.join(timeout=5)
226
if dec_rc != 0: