Clear the stranded tmpfs cache at startup
The session map is memory-only, so session directories surviving a restart can never be served and never be evicted -- and the work root is a tmpfs, so that is leaked RAM until reboot. The restart that ships the TTFB fix would have stranded 1.56 GB. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -735,6 +735,27 @@ def make_handler(mgr, wait_timeout, first_byte_grace=FIRST_BYTE_GRACE):
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def reset_work_root(path):
|
||||
"""Clear leftover session directories at startup. Returns bytes reclaimed.
|
||||
|
||||
The session map is in memory only, so anything already in the work root is
|
||||
unreachable after a restart: it can never be served (no session to find) and
|
||||
never be evicted (the cache accounting only sums tracked sessions). Since the
|
||||
work root is a tmpfs, leaving it there leaks RAM until the next reboot -- a
|
||||
restart with 1.56 GB cached stranded exactly that much.
|
||||
"""
|
||||
reclaimed = 0
|
||||
for name in os.listdir(path) if os.path.isdir(path) else []:
|
||||
stale = os.path.join(path, name)
|
||||
if not os.path.isdir(stale):
|
||||
continue
|
||||
out = os.path.join(stale, "out.mp4")
|
||||
if os.path.exists(out):
|
||||
reclaimed += os.path.getsize(out)
|
||||
shutil.rmtree(stale, ignore_errors=True)
|
||||
return reclaimed
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(
|
||||
description="just-in-time YouTube streaming proxy for Jellyfin")
|
||||
@@ -783,6 +804,11 @@ def main():
|
||||
_access_log = args.access_log
|
||||
|
||||
os.makedirs(args.work, exist_ok=True)
|
||||
stranded = reset_work_root(args.work)
|
||||
if stranded:
|
||||
log(f"cleared {stranded / 2**30:.2f} GB of untracked cache from "
|
||||
f"{args.work} left by a previous run")
|
||||
|
||||
mgr = Manager(args.work, args.max_pipelines,
|
||||
int(args.cache_gb * 2**30), args.no_fetch, args.growing,
|
||||
args.max_retries, args.max_starts, args.starts_window)
|
||||
|
||||
Reference in New Issue
Block a user