Skip to content

UnboundLocalError in _flush_events masks WASM trap errors #111

@jonathannorris

Description

@jonathannorris

Problem

_flush_events in event_queue_manager.py has a latent UnboundLocalError that masks underlying WASM errors.

# event_queue_manager.py:86
def _flush_events(self) -> int:
    if self._flush_lock.locked():
        return 0

    with self._flush_lock:
        try:
            payloads = self._local_bucketing.flush_event_queue()
        except Exception as e:
            logger.error(f"DevCycle: Error flushing event payloads: {str(e)}")

        event_count = 0
        if payloads:          # <-- UnboundLocalError if exception fired above
            ...
        return event_count

If flush_event_queue() raises (e.g. a WASMAbortError from the AssemblyScript bucketing engine trapping during flush), payloads is never assigned. The if payloads: check on line 97 then raises UnboundLocalError: local variable 'payloads' referenced before assignment.

The _flush_lock releases correctly (the with block handles that), but the UnboundLocalError propagates into run()'s generic except, which logs a vague warning. The original WASM error is effectively masked.

Context

Found during a cross-SDK audit related to dotnet-server-sdk #204, where the WASM bucketing engine traps during flush due to AssemblyScript throw new Error(...) (e.g. "Request Payload has not finished sending" in requestPayloadManager.ts:281).

The Python SDK does not have the same flush-mutex-leak as .NET (with self._flush_lock always releases), but it does have this related masking issue.

Suggested Fix

Initialize payloads before the try block:

payloads = []
try:
    payloads = self._local_bucketing.flush_event_queue()
except Exception as e:
    logger.error(f"DevCycle: Error flushing event payloads: {str(e)}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions