Skip to content

[DRAFT] - fix: add pg8000 graceful shutdown on Cloud Run scale-down#1669

Open
panish16 wants to merge 4 commits into
bcgov:mainfrom
panish16:fix/pg8000-graceful-shutdown
Open

[DRAFT] - fix: add pg8000 graceful shutdown on Cloud Run scale-down#1669
panish16 wants to merge 4 commits into
bcgov:mainfrom
panish16:fix/pg8000-graceful-shutdown

Conversation

@panish16
Copy link
Copy Markdown
Contributor

Summary

  • Registers a SQLAlchemy connect event listener on app startup that wraps each pg8000 connection's close() to suppress pg8000.exceptions.InterfaceError during Cloud Run scale-down
  • Fixes intermittent pg8000.exceptions.InterfaceError: network error logged when Cloud Run terminates idle instances and SQLAlchemy's connection pool teardown tries to close already-severed sockets
  • strr-email and strr-pay connect via Unix socket (no Cloud SQL Connector dependency), so the listener is implemented inline using the same logic

Services fixed

  • queue_services/strr-email/src/strr_email/__init__.py
  • queue_services/strr-pay/src/strr_pay/__init__.py

Test plan

  • Confirm no new pg8000.exceptions.InterfaceError entries in GCP Log Explorer for bcrbk9-prod project after deployment
  • Existing unit and integration test suites pass

Eliminates code duplication between strr-email and strr-pay by moving
the inline _setup_pg8000_graceful_shutdown function to strr_api/common/utils.py.
Also fixes SonarQube naming violation (_InterfaceError -> _interface_error).
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
6 Security Hotspots

See analysis details on SonarQube Cloud

@panish16 panish16 changed the title fix: add pg8000 graceful shutdown on Cloud Run scale-down [DRAFT] - fix: add pg8000 graceful shutdown on Cloud Run scale-down May 27, 2026
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.

1 participant