Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Bridge: wait up to 20 s for the device lease and name the busy lease in the failure report

Bowen Xue9bacb3302a0c
diff --git a/freevideo_engine/comfy_bridge.py b/freevideo_engine/comfy_bridge.py
index 1606790..31dcf63 100644
--- a/freevideo_engine/comfy_bridge.py
+++ b/freevideo_engine/comfy_bridge.py
@@ -22,6 +22,11 @@ from .comfy_environment import isolated_environment
from .monitoring import save
+# Longer than the idle encoder's yield window (YIELD_SECONDS plus its join slack), so a speculative
+# warm-up of the previous request on the same device releases the lease before the wait runs out.
+DEVICE_LEASE_WAIT_SECONDS = 20.
+
+
@contextlib.contextmanager
def _device_generation_lease(environment):
"""An executor of a multi-GPU pool holds its own device's lease, not the shared installation lock.
@@ -38,7 +43,7 @@ def _device_generation_lease(environment):
from .gpu_pool import child_lease_environment, generation_lease
from .locking import LOCK_ENV
device = SimpleNamespace(uuid=uuid)
- with generation_lease(device, wait_seconds=3) as descriptor:
+ with generation_lease(device, wait_seconds=DEVICE_LEASE_WAIT_SECONDS) as descriptor:
os.set_inheritable(descriptor, True)
environment.update(child_lease_environment(device), **{LOCK_ENV: str(descriptor)})
try:
@@ -1710,6 +1715,15 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
except BaseException as error:
cancelled = isinstance(error, KeyboardInterrupt) or type(error).__name__ in ('InterruptProcessingException', 'CancelledError')
state.update(status='cancelled' if cancelled else 'failed', error=repr(error))
+ if not cancelled:
+ try:
+ from .locking import busy_lock_details, failure_frames
+ state['traceback'] = failure_frames(error)
+ busy = busy_lock_details(error)
+ if busy:
+ state['busy_lock'] = busy
+ except Exception:
+ pass
try:
if cancelled:
# Windows may terminate the CLI before its finally block runs.
diff --git a/freevideo_engine/locking.py b/freevideo_engine/locking.py
index 2acd4a4..3cb0d13 100644
--- a/freevideo_engine/locking.py
+++ b/freevideo_engine/locking.py
@@ -254,6 +254,34 @@ def device_lock_path(device, path=None):
return base.with_name(base.stem + '-gpu-' + token + base.suffix)
+def name_busy_lock(error, path, shared, wait_seconds):
+ """Say which lease a refused acquisition wanted; the bare errno names nothing."""
+ path = Path(path)
+ token = path.stem.partition('-gpu-')[2]
+ error.busy_lock = dict(lock=('device lease ' + path.name.replace(token, token[:8]) if token
+ else 'installation lease ' + path.name),
+ shared=bool(shared), waited_seconds=round(wait_seconds, 3))
+ error.busy_lock_path = path
+
+
+def busy_lock_details(error):
+ """Name, wait and current holders of the lease an acquisition was refused, else {}."""
+ details = dict(getattr(error, 'busy_lock', None) or {})
+ if details:
+ try:
+ details['holders'] = describe_lock_holders([error.busy_lock_path])
+ except Exception:
+ pass
+ return details
+
+
+def failure_frames(error, limit=12):
+ """The traceback as 'file:line in function' rows: no source text, no folders, no values."""
+ import traceback
+ return ['%s:%d in %s' % (Path(frame.filename).name, frame.lineno, frame.name)
+ for frame in traceback.extract_tb(error.__traceback__)[-limit:]]
+
+
@contextmanager
def runtime_lock(path=None, *, inherit=True, shared=False, wait_seconds=0):
"""Take a lease, optionally waiting a bounded time for acquisition only."""
@@ -294,13 +322,15 @@ def runtime_lock(path=None, *, inherit=True, shared=False, wait_seconds=0):
import fcntl
fcntl.flock(stream, (fcntl.LOCK_SH if shared else fcntl.LOCK_EX) | fcntl.LOCK_NB)
break
- except BlockingIOError:
+ except BlockingIOError as error:
remaining = deadline - time.monotonic()
if remaining <= 0:
+ name_busy_lock(error, path, shared, wait_seconds)
raise
time.sleep(min(0.075, remaining))
# A delayed wakeup must not start another attempt after budget.
if time.monotonic() >= deadline:
+ name_busy_lock(error, path, shared, wait_seconds)
raise
# The body is outside the retry loop: a failed request must never rerun.
yield stream.fileno()
diff --git a/freevideo_engine/support_report.py b/freevideo_engine/support_report.py
index ddd114f..fecab5b 100644
--- a/freevideo_engine/support_report.py
+++ b/freevideo_engine/support_report.py
@@ -501,7 +501,7 @@ def write(output, report=None, bridge=None, *, _retry=None, live=False, restarte
encoding=request.get('encoding_resources') or dict(ram=read_json('.encoding.memory.json')),
scope='Keep working RAM, PSS/RSS, commit and whole-GPU/allocator observations separate. '
'Cached encoder receipts do not describe this request’s peak.'),
- bridge={k:bridge[k] for k in ('status', 'error', 'bridge_seconds', 'bridge_wall_seconds', 'sampling_cache_install', 'encoder_prewarm') if k in bridge},
+ bridge={k:bridge[k] for k in ('status', 'error', 'bridge_seconds', 'bridge_wall_seconds', 'sampling_cache_install', 'encoder_prewarm', 'traceback', 'busy_lock') if k in bridge},
collection_notes=notes, log_tails={})
stalled = agent_video_stalls(bridge.get('agent_generation_jobs') or
agent_poll.get('agent_generation_jobs'))