Skip to content

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

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

fix: add pg8000 graceful shutdown on Cloud Run scale-down#1669
panish16 wants to merge 3 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

@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
@panish16 panish16 changed the title [DRAFT] - fix: add pg8000 graceful shutdown on Cloud Run scale-down fix: add pg8000 graceful shutdown on Cloud Run scale-down Jun 8, 2026
@panish16 panish16 force-pushed the fix/pg8000-graceful-shutdown branch from 09921be to 2b071bb Compare June 8, 2026 23:06
@panish16 panish16 force-pushed the fix/pg8000-graceful-shutdown branch from 2b071bb to 3780bf5 Compare June 10, 2026 21:38
@panish16 panish16 requested a review from jimmypalelil as a code owner June 10, 2026 21:38
@sonarqubecloud

Copy link
Copy Markdown

@Jacky-Pham Jacky-Pham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@@ -1,4 +1,186 @@
# This file is automatically @generated by Poetry 2.3.4 and should not be changed by hand.
# This file is automatically @generated by Poetry 2.3.2 and should not be changed by hand.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

poetry version is mismatched. is that intended?

@@ -1,4 +1,186 @@
# This file is automatically @generated by Poetry 2.3.4 and should not be changed by hand.
# This file is automatically @generated by Poetry 2.3.2 and should not be changed by hand.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same comment here as above about the poetry version

Comment thread .sonarcloud.properties
# Path to sources
#sonar.sources=strr-api/src/**/*
sonar.exclusions=strr-api/migrations/**/*,strr-api/devops/**/*,strr-api/tests/**/*,testing/**/*
sonar.exclusions=strr-api/migrations/**/*,strr-api/devops/**/*,strr-api/tests/**/*,testing/**/*,queue_services/**/tests/**/*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

whats the reason for adding this?

@jimmypalelil

Copy link
Copy Markdown
Collaborator

hey @panish16 thanks for integrating the cloud-sql-connector lib. Its only applied to couple python proejcts. Should it not be applied to all that depend on the DB?

assert stored.meta_data["email_type"] == "STRATA_HOTEL_REGISTRATION_ACTIVE"


def test_email_no_cloud_event_data(client, queue_envelope, simple_cloud_event):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what are these unit & integration tests added for in this project?

wasnt it already at 100% coverage?

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.

4 participants