You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR addresses the OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly occurring in app.tasks.upload.UploadFinisher.
Root Cause: UploadFinisher tasks were encountering SoftTimeLimitExceeded or PostgreSQL's idle_in_transaction_session_timeout because DB sessions were held open across long-running non-database operations. This resulted in the database connection being unexpectedly closed, leading to an OperationalError when db_session.commit() was subsequently called on the dead connection.
Changes Made:
Reset DB connection in _handle_finisher_lock: After finish_reports_processing completes its potentially long-running operations, a db_session.rollback() is now explicitly called. This releases the potentially stale connection back to the pool. With pool_pre_ping enabled, the next database operation will acquire a fresh or validated connection, preventing errors from idle timeouts.
Commit commit.state = "skipped" immediately: In finish_reports_processing, the commit.state = "skipped" change (for CI skip tags) is now immediately followed by a db_session.commit(). This ensures the change is persisted to the database before the db_session.rollback() in the calling function can discard it.
These changes ensure proper management of database connections around intensive processing, mitigating connection timeouts and operational errors.
Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
This PR mitigates the OperationalError in UploadFinisher by rolling back the DB session after the long-running finish_reports_processing call (releasing a potentially stale connection so pool_pre_ping can revalidate it), and by committing commit.state = "skipped" immediately in the CI-skip branch so it survives that rollback. The change is well-scoped: all DB mutations that precede the rollback are already committed — the report save commits at _process_reports_with_lock, mark_uploads_as_merged is Redis-only, and the notify/skip branches each commit their own ORM writes — so the new rollback discards no pending work.
❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (17e0f08) to head (cff597b).
✅ All tests successful. No failed tests found.
❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.
📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the
OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedlyoccurring inapp.tasks.upload.UploadFinisher.Root Cause:
UploadFinishertasks were encounteringSoftTimeLimitExceededor PostgreSQL'sidle_in_transaction_session_timeoutbecause DB sessions were held open across long-running non-database operations. This resulted in the database connection being unexpectedly closed, leading to anOperationalErrorwhendb_session.commit()was subsequently called on the dead connection.Changes Made:
_handle_finisher_lock: Afterfinish_reports_processingcompletes its potentially long-running operations, adb_session.rollback()is now explicitly called. This releases the potentially stale connection back to the pool. Withpool_pre_pingenabled, the next database operation will acquire a fresh or validated connection, preventing errors from idle timeouts.commit.state = "skipped"immediately: Infinish_reports_processing, thecommit.state = "skipped"change (for CI skip tags) is now immediately followed by adb_session.commit(). This ensures the change is persisted to the database before thedb_session.rollback()in the calling function can discard it.These changes ensure proper management of database connections around intensive processing, mitigating connection timeouts and operational errors.
Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
Fixes WORKER-Z7D
This PR was automatically generated by Sentry. You can adjust this setting at any time.