Skip to content

fix(worker): improve Bitbucket API error handling for diffs#1224

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-bitbucket-diff-error
Open

fix(worker): improve Bitbucket API error handling for diffs#1224
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/worker-bitbucket-diff-error

Conversation

@sentry

@sentry sentry Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue WORKER-YTS, where TorngitServerUnreachableError was being raised misleadingly when Bitbucket dropped a connection mid-stream while serving a large diff.

Root Cause:
Bitbucket was reachable and returned 200 OK, but then closed the TCP connection before the full diff response body was transmitted. This resulted in an httpx.ReadError (a type of httpx.NetworkError), which was then caught by shared/torngit/bitbucket.py and re-raised as a generic TorngitServerUnreachableError. The ComputeComparison task did not explicitly handle this specific error, leading to task failures.

Changes Implemented:

  1. apps/worker/tasks/compute_comparison.py:
    • Imported TorngitServerUnreachableError for explicit handling.
    • Wrapped the comparison_proxy.get_patch_totals() call in a try/except block to catch TorngitServerUnreachableError. Upon catching, the task now logs a warning, sets the comparison state to error, and returns gracefully with an appropriate error message.
    • Extended the existing try/except block for comparison_proxy.get_impacted_files() to also catch TorngitServerUnreachableError, ensuring consistent error handling for Bitbucket API calls within the task.
  2. libs/shared/shared/torngit/bitbucket.py:
    • Modified the _send_request method to differentiate between various network errors. A specific except httpx.ReadError block was added before the more general httpx.NetworkError catch. This allows for a more precise TorngitServerUnreachableError message, indicating a "connection dropped mid-response" when a ReadError occurs, providing better context for debugging.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry 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 Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes WORKER-YTS

@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing seer/fix/worker-bitbucket-diff-error (176b585) with main (ee7a2b4)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (7b60783) during the generation of this report, so ee7a2b4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.89%. Comparing base (7b60783) to head (176b585).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/bitbucket.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1224      +/-   ##
==========================================
- Coverage   91.89%   91.89%   -0.01%     
==========================================
  Files        1325     1325              
  Lines       50862    50862              
  Branches     1626     1626              
==========================================
- Hits        46741    46740       -1     
- Misses       3815     3816       +1     
  Partials      306      306              
Flag Coverage Δ
apiunit 94.95% <ø> (ø)
sharedintegration 36.89% <0.00%> (-0.01%) ⬇️
sharedunit 84.86% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codecov-notifications

codecov-notifications Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/bitbucket.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

0 participants