Skip to content

fix(spanner): CrossSync.queue_get with timeout <= 0 fails immediately even when queue is non-empty #19107

Open

Description

@olavloite

Summary

In packages/google-cloud-spanner/google/cloud/aio/_cross_sync/cross_sync.py, CrossSync.queue_get implements timeout using asyncio.wait_for(queue.get(), timeout=timeout):

if timeout is not None:
    try:
        return await asyncio.wait_for(queue.get(), timeout=timeout)
    except asyncio.TimeoutError:
        raise CrossSync.QueueEmpty()

When timeout <= 0 (for example, AsyncFixedSizePool(size=1, default_timeout=0) or AsyncPingingPool(size=1, default_timeout=0)), asyncio.wait_for(queue.get(), timeout=0) in Python 3.14 cancels queue.get() and raises asyncio.TimeoutError (asyncio.QueueEmpty) immediately even when the queue already contains an available session.

In contrast, the synchronous queue.Queue.get(block=True, timeout=0) returns an item immediately if one is in the queue and only raises queue.Empty if the queue is empty.

Expected Fix

Handle timeout <= 0 (or not block) via queue.get_nowait() in CrossSync.queue_get:

if not block or (timeout is not None and timeout <= 0):
    try:
        return queue.get_nowait()
    except asyncio.QueueEmpty:
        raise CrossSync.QueueEmpty()

This matches the synchronous queue.Queue.get(block=True, timeout=0) behavior with zero timer/scheduling overhead.

Activity

  1. self-assigned this
    on Nov 17, 2026
  2. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: spannerIssues related to the Spanner API.
    on Nov 17, 2026
  3. daniel-sanche commented on Nov 17, 2026

    @daniel-sanche
    Contributor

    Would you be in favor of us adding CrossSync to api_core, so we can avoid maintaining duplicate copies across spanner and bigtable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the Spanner API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions