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

[SYNPY-1514] Handle Expired Pre-Signed URLs #1126

Merged
merged 40 commits into from
Sep 4, 2024

Conversation

BWMac
Copy link
Contributor

@BWMac BWMac commented Aug 29, 2024

Problem:

Due to the unordered nature of AsyncIO executing tasks async, when there is a large queue of files to download, the file may not be downloaded for a while after a pre-signed URL is retrieved. This shows up as a 403 Forbidden error which needs to be handled for these cases to prevent downloads from failing.

Solution:

Update download_from_url to handle these 403 responses and try again by checking if the URL is expired when we receive a 403 response code, retrieving a new URL and retrying the download.

Testing:

  • This was tested by:
    1. Reproducing the error faced by a user by using the random package to have this failure occur.
    2. Hard-coding an expired URL into the code and running a synapse get CLI command
  • new unit and integration tests were added

@pep8speaks
Copy link

pep8speaks commented Aug 29, 2024

Hello @BWMac! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 744:89: E501 line too long (93 > 88 characters)
Line 756:89: E501 line too long (103 > 88 characters)
Line 776:89: E501 line too long (97 > 88 characters)
Line 788:89: E501 line too long (121 > 88 characters)

Line 21:1: F401 'synapseclient.core.exceptions' imported but unused
Line 23:1: F401 'synapseclient.core.exceptions.SynapseHTTPError' imported but unused

Line 680:89: E501 line too long (90 > 88 characters)
Line 725:89: E501 line too long (92 > 88 characters)
Line 860:89: E501 line too long (93 > 88 characters)
Line 863:89: E501 line too long (90 > 88 characters)
Line 925:89: E501 line too long (93 > 88 characters)
Line 928:89: E501 line too long (90 > 88 characters)

Comment last updated at 2024-09-03 22:11:44 UTC

@BWMac BWMac marked this pull request as ready for review August 30, 2024 18:27
@BWMac BWMac requested a review from a team as a code owner August 30, 2024 18:27
@BryanFauble
Copy link
Contributor

There was also an SSL exception that was in the logs the user had provided. Can you also see if we can add that to the exceptions that are retried?

@BWMac
Copy link
Contributor Author

BWMac commented Aug 30, 2024

@BryanFauble We definitely could, but as written my solution to the 403 response codes is to check if the URL is expired and then if it is, retry. Will the URL also be expired in the case where SSLZeroReturnError is raised or should this case bypass the URL check/refresh?

@BryanFauble
Copy link
Contributor

@BryanFauble We definitely could, but as written my solution to the 403 response codes is to check if the URL is expired and then if it is, retry. Will the URL also be expired in the case where SSLZeroReturnError is raised or should this case bypass the URL check/refresh?

I don't think a 403 is going to be raised. I think the solution is to add it to the standard retry params:

"retry_exceptions": RETRYABLE_CONNECTION_EXCEPTIONS,

In the retry function you can also pass the actual exception class too. I think we will want to add it as one of the things to retry, just like the connection exceptions that are raised. That way the ssl errors are treated with the same 5 minute retry logic.

Copy link
Contributor

@BryanFauble BryanFauble left a comment

Choose a reason for hiding this comment

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

Great changes! Just a few small areas that changes could be made, but shouldn't affect overall intention of the code.

Copy link
Contributor

@BryanFauble BryanFauble left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@thomasyu888 thomasyu888 left a comment

Choose a reason for hiding this comment

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

🔥 LGTM! This is neat, although the exception handling definitely looks more complex now.

@BWMac BWMac merged commit 1b48d02 into develop Sep 4, 2024
22 of 23 checks passed
@BWMac BWMac deleted the bwmac/SYNPY-1514/download_from_url_retry_update branch September 4, 2024 01:01
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.

4 participants