cmds.secrets.lib.DistroContext: Hold ctx + store open
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m49s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 6m6s
CI / Packaging test (pull_request) Successful in 0s

Each run() call opens and closes the exec context, so a compile that issues
one remote command at a time opened and closed the SSH connection for every
command: a single deploy on dynamix opened around a hundred sessions and
took several minutes.

run() opens and closes through the FileContext reference counter, so
holding the context (and the secret store) open for the whole compile turns
the per-command open() / close() pairs into counter bumps, and the
connection is established only once. This commit wraps the target listing
and the per-target loop in an "async with" on both, which drops the counter
to zero at end of scope and closes the contexts.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-11-20 05:22:27 +01:00
commit 7cec4007da
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -90,20 +90,25 @@ class DistroContext(FilesContext):
ret: list[str] = []
failed: list[str] = []
missing = 0
targets = await self.list_compilation_targets(pkg_names)
for target in targets:
try:
ok = await self.compile_template_file(target, default_attrs)
except Exception as e:
if not keep_going:
raise
log(ERR, f'{target}: {e}')
failed.append(target)
continue
if ok:
ret.append(target)
else:
missing += 1
# -- Keep the exec context and the store open across the whole
# compile, so the run() calls in the per-target operations
# bump the reference counter instead of opening and closing
# the connection for every remote command.
async with self.ctx, self.store:
targets = await self.list_compilation_targets(pkg_names)
for target in targets:
try:
ok = await self.compile_template_file(target, default_attrs)
except Exception as e:
if not keep_going:
raise
log(ERR, f'{target}: {e}')
failed.append(target)
continue
if ok:
ret.append(target)
else:
missing += 1
if missing > 0:
from ....lib.util import pretty_cmd