MCPcopy
hub / github.com/usestrix/strix / cleanup

Function cleanup

strix/runtime/session_manager.py:106–133  ·  view source on GitHub ↗

Tear down ``scan_id``'s container and drop its cache entry. Best-effort: any error during ``client.delete`` is logged and swallowed. We never want a cleanup failure to prevent the next scan from starting; the worst case is a stranded container that Docker's normal reaping will catch

(scan_id: str)

Source from the content-addressed store, hash-verified

104
105
106async def cleanup(scan_id: str) -> None:
107 """Tear down ``scan_id``'s container and drop its cache entry.
108
109 Best-effort: any error during ``client.delete`` is logged and
110 swallowed. We never want a cleanup failure to prevent the next
111 scan from starting; the worst case is a stranded container that
112 Docker's normal reaping will catch on next ``docker prune``.
113 """
114 bundle = _SESSION_CACHE.pop(scan_id, None)
115 if bundle is None:
116 logger.debug("cleanup(%s): no cached session", scan_id)
117 return
118
119 caido_client = bundle.get("caido_client")
120 if caido_client is not None:
121 try:
122 await caido_client.aclose()
123 except Exception: # noqa: BLE001
124 logger.debug("cleanup(%s): caido_client.aclose() raised", scan_id, exc_info=True)
125
126 try:
127 await bundle["client"].delete(bundle["session"])
128 logger.info("Cleaned up sandbox session for scan %s", scan_id)
129 except Exception:
130 logger.exception(
131 "cleanup(%s): client.delete raised; container may need manual reaping",
132 scan_id,
133 )

Callers

nothing calls this directly

Calls 1

deleteMethod · 0.80

Tested by

no test coverage detected