Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions rampart/attacks/_xpia.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,22 @@ async def _activate_handles_async(
Args:
stack (AsyncExitStack): The exit stack managing cleanup.
"""
for handle in self._handles:
await stack.enter_async_context(handle)

# Concurrent: total = max of all wait times
async def _enter_handle(h: InjectionHandle) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter flagged: async function _enter_handle must be named with an _async suffix (e.g. _enter_handle_async) to pass through CI

await stack.enter_async_context(h)

# Concurrent context entry (network uploads)
try:
async with asyncio.TaskGroup() as tg:
for handle in self._handles:
tg.create_task(_enter_handle(handle))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TaskGroup cancels the remaining __aenter__ calls as soon as one handle fails. A sibling may already have created its remote payload but be cancelled before enter_async_context() can register its __aexit__, leaving that payload orphaned.

Please replace _enter_handle and the first TaskGroup block with a non-cancelling gather; this belongs directly in _activate_handles_async, before the existing readiness-wait block:

results = await asyncio.gather(
    *(stack.enter_async_context(handle) for handle in self._handles),
    return_exceptions=True,
)
errors = [result for result in results if isinstance(result, BaseException)]
if errors:
    raise errors[0]

# Keep the existing readiness TaskGroup here.

This preserves concurrent activation while allowing successful siblings to register cleanup.

Please also add unit tests: a regression test where one handle fails immediately and another finishes activation after a delay would cover the partial-failure case.

except ExceptionGroup as eg:
# Unwrap the first exception for cleaner error reporting.
# BaseExecution already catches and reports exceptions,
# but ExceptionGroup obscures the underlying InfrastructureError.
raise eg.exceptions[0] from eg
Comment thread
apocalypse9949 marked this conversation as resolved.

# Concurrent readiness wait (indexing delays)
async with asyncio.TaskGroup() as tg:
for handle in self._handles:
tg.create_task(handle.wait_until_ready())
Expand Down
Loading