Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Deadlock due to race condition in download thread when using Bigquery Storage API #2032

Description

@kien-truong

There is a race condition in the download thread and the main thread when using Bigquery Storage API to fetch data.

for page in rowstream.pages:
if download_state.done:
return
item = page_to_item(page)
worker_queue.put(item)

finally:
# No need for a lock because reading/replacing a variable is
# defined to be an atomic operation in the Python language
# definition (enforced by the global interpreter lock).
download_state.done = True
# Shutdown all background threads, now that they should know to
# exit early.
pool.shutdown(wait=True)

When the download thread is blocked on worker_queue.put(item), if the main thread exit, causing the pool to shut down, the download thread will be stuck. This behavior prevents the program from exiting.

Activity

  1. added
    api: bigquery
    on Sep 26, 2024
  2. added
    type: bug
    priority: p3
    on Oct 2, 2024
  3. kien-truong commented on Nov 16, 2024

    @kien-truong
    ContributorAuthor

    @chalmerlowe can you take a look at this issue and my corresponding PR #2034? thanks

  4. tswast commented on Feb 3, 2025

    @tswast
    Contributor

    FWIW: We think this was affecting the BigQuery DataFrames benchmark tests. Basically, if one starts iterating through the dataframe pages but then stops iterating through, the workers would stay producing messages and never go totally out of scope / shutdown.

  5. self-assigned this
    on Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigquerypolicybotpriority: p3type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions