Skip to content

Sending AppendRowsRequest 5 minutes after last request causes google.api_core.exceptions.Unknown: None There was a problem opening the stream. Try turning on DEBUG level logs to see the error. #15693

Closed as not planned

Description

@chef-kyle

Environment details

  • OS type and version: Dockerized Linux
  • Python version: 3.11
  • pip version: uv 0.8.9
  • google-cloud-bigquery version: 3.38.0

Steps to reproduce

Reproduction steps are a little bare, I'm unsure what what levels resources are pooled, and it takes some time/luck to hit this condition.

  1. Send an AppendRowsRequest
  2. Wait 5 minutes for the stream to start reconnecting
  3. If debug logging for bidi enabled, see something like Closing the stream because it has been inactive for 600 seconds. Entity: ...
  4. Send another AppendRowsRequest to the same resource
  5. google.api_core.exceptions.Unknown: None There was a problem opening the stream. Try turning on DEBUG level logs to see the error."

Generally, the application is part of a pool of Cloud Run instances - under certain workloads the instance would have around 5 minutes of idle time between requests.

Generally, calling close() on the writer.AppendRowsStream after you are done with it appears to mitigate most of the issues, but there isn't a documented need for this, nor does it solve all cases (what if I have 5 minutes of work I need to do somewhere else?)

Code example

Not full reproduction, but an example of the way I'm using the API

        RowMessage, row_descriptor = make_message_class(table, self.table_name)
        proto_schema = bigquery_storage_v1.types.ProtoSchema(
            proto_descriptor=row_descriptor
        )

        batched_rows = []
        current_batch_size = self._MAX_QUERY_SIZE_IN_BYTES
        for _, row in self.final_data.iterrows():
            fields = {m.name: row[m.name] for m in table.schema}

            serialized_msg = RowMessage(**fields).SerializeToString()
            row_size = len(serialized_msg)
            if (
                current_batch_size + row_size > self._MAX_QUERY_SIZE_IN_BYTES * 0.8
                or len(batched_rows[-1].serialized_rows) >= self._MAX_CHUNK_SIZE
            ):
                batched_rows.append(ProtoRows())
                current_batch_size = 0
            current_batch_size += row_size
            batched_rows[-1].serialized_rows.append(serialized_msg)

        request_template = AppendRowsRequest()

        request_template.write_stream = write_stream_path

        # Generating the protocol buffer representation of the message descriptor.
        proto_data = AppendRowsRequest.ProtoData()
        proto_data.writer_schema = proto_schema
        request_template.proto_rows = proto_data

        # TODO(kyle): later on, we can share the stream between all jobs,
        # and only commit once all rows are loaded, if we want
        self.append_rows_stream = writer.AppendRowsStream(
            self.bq_write_client, request_template
        )

        for batch in batched_rows:
            request = AppendRowsRequest()
            proto_data = AppendRowsRequest.ProtoData()
            proto_data.rows = batch
            request.proto_rows = proto_data

Stack trace

Stack trace shows 3.14 but issue appears on all versions of python tested.

  File "/app/.venv/lib/python3.14/site-packages/google/cloud/bigquery_storage_v1/writer.py", line 167, in send
    return self._connection.send(request)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/app/.venv/lib/python3.14/site-packages/google/cloud/bigquery_storage_v1/writer.py", line 425, in send
    return self.open(request)
           ~~~~~~~~~^^^^^^^^^
  File "/app/.venv/lib/python3.14/site-packages/google/cloud/bigquery_storage_v1/writer.py", line 297, in open
    return self._open(initial_request, timeout)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.14/site-packages/google/cloud/bigquery_storage_v1/writer.py", line 380, in _open
    raise request_exception
google.api_core.exceptions.Unknown: None There was a problem opening the stream. Try turning on DEBUG level logs to see the error."
timestamp: "2025-11-24T19:58:03.025145Z"

Turning on DEBUG logs in general does NOT show the error. I was only able to find the error by specifically enabling the bidi logger using code like

    bidi_logger = logging.getLogger("google.api_core.bidi")
    bidi_logger.setLevel(logging.DEBUG)

    bidi_handler = logging.StreamHandler()  # or FileHandler("bidi.log")
    bidi_handler.setLevel(logging.DEBUG)
    bidi_handler.setFormatter(
        logging.Formatter("[%(asctime)s] %(name)s %(levelname)s: %(message)s")
    )

    bidi_logger.addHandler(bidi_handler)
    bidi_logger.propagate = False

At which point you can actually look at the underlying behavior of the library

Activity

  1. added
    api: bigquery
    on Nov 25, 2025
  2. removed their assignment
    on Nov 25, 2025
  3. parthea commented on Jan 12, 2026

    @parthea
    Contributor

    Transferring to google-cloud-python as the code for python-bigquery will be migrated there in 1-3 weeks.

  4. parthea commented on Jan 12, 2026

    @parthea
    Contributor

    Transferring this issue back to python-bigquery.

  5. chalmerlowe commented on Mar 2, 2026

    @chalmerlowe
    Contributor

    This issue was moved from the following repo as part of the monorepo migration: googleapis/python-bigquery

  6. added
    api: bigquery
    on Mar 2, 2026
  7. daniel-sanche commented on May 28, 2026

    @daniel-sanche
    Contributor

    This issue is being bulk closed due to inactivity. Please re-open if you think this still requires attention, and we'll take another look. Thanks!

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

Metadata

Metadata

Assignees

Labels

api: bigquery

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions