bcgov / bcgov/entity

Implement pg8000 graceful shutdown and error handling for database connection error

Open
#33,564 0 comments 0 reactions 1 assignee Claimed by @panish16 View on GitHub
SRE
Dominant language
JavaScript
Stars
23
Forks
62
Avg merge
24m
Merged PRs (30d)
1

Description

**Summary**

Implement graceful shutdown and improved error handling for pg8000 database connections using setup_pg8000_close_event_listener from the Cloud SQL Python Connector to reduce connection‑related errors and improve application reliability.

**Background**

The application is currently experiencing frequent pg8000 database connection errors, indicating that connections are not being properly closed or managed during:

- Application shutdown

- Container lifecycle events (Cloud Run)

- Transient failures or restarts

image.png

image.png

**Proposed Solution**

Implement proper connection lifecycle management in each application (as identified in logs) by:

https://github.com/bcgov/sbc-connect-common/blob/main/python/cloud-sql-connector/src/cloud_sql_connector/connector.py#L150

image.png

Ensuring:

- Database connections are gracefully closed on application/container shutdown

- Errors are handled explicitly (retry/backoff where appropriate)

- Connection handling aligns with Cloud Run lifecycle best practices

## Acceptance Criteria

- [ ] As a first step, please identify all applications that may be impacted, based on the issues identified in the logs or Error report from GCP Monitor.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.