Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RisingOrange
Copy link
Collaborator

@RisingOrange RisingOrange commented Feb 15, 2025

Fixes an error users were occasionally getting in the reviewer when not logged in.
https://ankihub.sentry.io/issues/6253435393/events/f027550d1cb344b9ad9a5cb6b6c3aa9c/?project=6546414

Also makes some other improvements to the handling of 401 exceptions in the reviewer.

Related issues

https://ankihub.sentry.io/issues/6253435393/events/f027550d1cb344b9ad9a5cb6b6c3aa9c/?project=6546414
https://community.ankihub.net/t/got-an-error-message/397521

Proposed changes

The error was caused by our exception handler raising an exception while handling an 401 AnkiHubHTTPError.
The exception handler raised an exception because it was calling config.save_token(), which in turn called the callbacks in config.token_change_hook.
One of the callbacks (update_feature_flags_in_background) called aqt.mw.taskman.run_in_background.
aqt.mw.taskman.run_in_background runs any pending closures from tasks that just finished.
One of the pending closures re-raised an exception which was raised in the associated background task.

Summarizing, the issue is that calling aqt.mw.taskman.run_in_background() can raise an exception if there were was an exception in a (possibly unrelated) background task that was just run. (When this happens, the new background task is not run.)

This is something that should probably be fixed in Anki.

For now, the fix that this PR applies is to use aqt.mw.taskman.run_on_main() to call functions which call aqt.mw.taskman.run_in_background() in some relevant places. Using aqt.mw.taskman.run_on_main(closure) prevents exceptions raised by the closure from getting backpropagated to the caller.
So, the code which calls aqt.mw.taskman.run_in_background, won't be interrupted the exception. (The background task which it tried to start won't be run though.)

We used this technique before in this decorator:

def pass_exceptions_to_on_done(func: Callable) -> Callable:

Other fixes/improvements:

Notes

Logs which were helpful while debugging the error:
https://app.datadoghq.com/logs?query=host%3Ashannons-air.dhcp.swmed.org%20service%3Aankihub_addon&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&context_event=AZUBBKq2AABE-P7_kAS1CQAK&fromUser=true&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=time%2Casc&viz=&from_ts=1739478517555&to_ts=1739480376381&live=false

@RisingOrange RisingOrange requested a review from a team February 17, 2025 13:25
@RisingOrange RisingOrange merged commit 5aa7479 into main Feb 18, 2025
7 checks passed
@RisingOrange RisingOrange deleted the fix/exception-in-exception-handler branch February 18, 2025 15:54
@sentry
Copy link

sentry bot commented Feb 26, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ AnkiHubRequestException: AnkiHub request exception: HTTPSConnectionPool(host='app.ankihub.net', port=443): Max retries exceeded with url: /api/decks/generate-presigned-url?key=ankihub_addon_debug_info_not_signed_in_1740546584.zip&type=upload&many=false (Caused by SSLError(SSLCe... 1322529746.ankihub_client.ankihub_client in _se... View Issue
  • ‼️ AnkiHubHTTPError: AnkiHub request error: 403 Forbidden 1322529746.addon_ankihub_client in upload_logs View Issue

Did you find this useful? React with a 👍 or 👎

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.

3 participants