Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: better handle CancelledError from static analysis #275

Merged

Conversation

giovanni-guidini
Copy link
Contributor

context: codecov/engineering-team#643

Currently static analysis command is still very delicate and breaks easily.
Not so much (anymore) in the analysis part, but the uploading of files, specially in the first few runs, can cause indecipherable stack traces that simply state CancelledError was thrown.

This PR introduces some error handling for send_single_upload_put function and the general gathering of many such tasks in the hopes that we can fail gracefully (and not land on your face)

Instead of failing (and raising) in the case of a request exception (in `send_single_upload_put`)
we will now catch the exception, emit warning, and return safely.

This is important because the aggregate of all tasks WILL fail if one of the requests fail.
Also notice that `httpx.HTTPError` is the base error class for a number of request-related errors,
so this covers many of the failure possibilities here
We have seen stacktraces of static analysis failing with
`asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f7514b8ffa0`

I do believe that the initial cause is one of the requests failing, and that cancels every other task, but
there's a still possible scenario in which the outer future (`asyncio.gather itself`) gets cancelled.

Assuming that it happens and that we do get the same exception bubble up, these changes would
let the program exit (more) gracefully.

Maybe there are other exceptions there that we should also look for?
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #275 (0fed329) into master (40483bb) will increase coverage by 0.42%.
The diff coverage is 95.00%.

@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
+ Coverage   94.91%   95.34%   +0.42%     
==========================================
  Files          78       78              
  Lines        2696     2708      +12     
==========================================
+ Hits         2559     2582      +23     
+ Misses        137      126      -11     
Flag Coverage Δ
python3.10 95.62% <95.00%> (+0.39%) ⬆️
python3.11 95.62% <95.00%> (+0.39%) ⬆️
python3.8 95.62% <95.00%> (+0.39%) ⬆️
python3.9 95.66% <95.00%> (+0.42%) ⬆️
smart-labels 95.30% <95.00%> (+0.39%) ⬆️

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

Files Coverage Δ
codecov_cli/services/staticanalysis/__init__.py 90.07% <95.00%> (+9.45%) ⬆️

"succeeded": True,
}
if response.status_code in retryable_statuses:
await asyncio.sleep(2**current_retry)
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be good to write a test that covers this line but otherwise lgtm

@giovanni-guidini giovanni-guidini merged commit c42fe0b into master Oct 5, 2023
10 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/handle-static-analysis-put-failures-better branch October 5, 2023 15:26
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.

2 participants