reflex-dev/reflex · error · RuntimeError

Upload chunk iterator is closed.

Error message

Upload chunk iterator is closed.

What it means

The upload chunk iterator is a bounded queue; push() blocks while full and raises RuntimeError if the queue was closed (upload finished or aborted) while a producer was blocked or about to enqueue. This prevents writing chunks after the consumer is gone.

Source

Thrown at packages/reflex-components-core/src/reflex_components_core/core/_upload.py:207

        task.add_done_callback(self._wake_waiters)

    async def push(self, chunk: UploadChunk) -> None:
        """Push a new chunk into the iterator.

        Args:
            chunk: The chunk to push.

        Raises:
            RuntimeError: If the iterator is already closed or the consumer exited early.
        """
        async with self._condition:
            while len(self._chunks) >= self._maxsize and not self._closed:
                self._raise_if_consumer_finished()
                await self._condition.wait()

            if self._closed:
                msg = "Upload chunk iterator is closed."
                raise RuntimeError(msg)

            self._raise_if_consumer_finished()
            self._chunks.append(chunk)
            self._condition.notify_all()

    async def finish(self) -> None:
        """Mark the iterator as complete."""
        async with self._condition:
            if self._closed:
                return
            self._closed = True
            self._condition.notify_all()

    async def fail(self, error: Exception) -> None:
        """Mark the iterator as failed.

        Args:
            error: The error to raise from the iterator.

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Ensure the upload handler consumes the full iterator (don't break early on partial reads)
  2. Handle client disconnects upstream so the parser stops pushing chunks
  3. Catch RuntimeError around push/consume loops in custom upload plumbing and treat it as cancellation
Defensive patterns

Strategy: try-catch

Try / catch

try:
    await iterator.push(chunk)
except RuntimeError:
    # upload closed (disconnect/finish) — stop producing
    abort_parse()

Prevention

When it happens

Trigger: Server-side upload machinery pushes a chunk after iterator.close() was called — typically when the client disconnected, the handler returned early, or the request was cancelled mid-stream.

Common situations: Client aborts a large file upload mid-transfer; websocket/http disconnect while chunks are still being forwarded; handler breaks out of the loop before draining the iterator.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/55e4821b0cf492d1. Report an issue: GitHub.