Skip to content

test(bigquery): add debug info to socket leak test - #17802

Merged
chalmerlowe merged 1 commit into
mainfrom
fix/bigquery-socket-leak-debug
Jul 21, 2026
Merged

test(bigquery): add debug info to socket leak test#17802
chalmerlowe merged 1 commit into
mainfrom
fix/bigquery-socket-leak-debug

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

The system test test_dbapi_connection_does_not_leak_sockets has been failing intermittently with minor socket count discrepancies (e.g., 7 instead of 6). Previous attempts to fix this have not fully eliminated the flakiness, likely due to non-deterministic garbage collection or Operating System cleanup delays. Without knowing the exact state of these "leaked" sockets (e.g., TIME_WAIT vs CLOSE_WAIT), it is difficult to determine if this is a real resource leak in the application or just OS noise.

Solution

This PR wraps the socket count assertion in a try...except AssertionError block. If the assertion fails, it captures the status, local address, and remote address of all active network connections for the current process and appends this information to the failure message.

Notes to Reviewers

  • This change does not attempt to fix the underlying flakiness or leak. It is purely diagnostic.
  • The detailed socket state will help us distinguish between expected OS delays (TIME_WAIT) and real application leaks (CLOSE_WAIT or ESTABLISHED) in future CI/CD runs.
  • This approach avoids running expensive system tests repeatedly to try and capture an intermittent failure manually.

@chalmerlowe chalmerlowe changed the title feat(bigquery): add debug info to socket leak test test(bigquery): add debug info to socket leak test Jul 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a try-except block to capture and log detailed socket connection debug information when the test_dbapi_connection_does_not_leak_sockets test fails. The review feedback correctly identifies that current_process.net_connections() is not a valid method and will raise an AttributeError, masking the assertion failure, and suggests using current_process.connections() instead.

Comment thread packages/google-cloud-bigquery/tests/system/test_client.py
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 21, 2026 17:41
@hebaalazzeh
hebaalazzeh requested review from a team as code owners July 21, 2026 17:41
@hebaalazzeh
hebaalazzeh requested review from hebaalazzeh and sycai and removed request for a team July 21, 2026 17:41
@chalmerlowe
chalmerlowe merged commit 2a2dc83 into main Jul 21, 2026
39 checks passed
@chalmerlowe
chalmerlowe deleted the fix/bigquery-socket-leak-debug branch July 21, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants