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

if curl fails, print a warning instead of exiting #1137

Merged
merged 2 commits into from
Dec 26, 2024

Conversation

lesomnus
Copy link
Contributor

@lesomnus lesomnus commented Jul 24, 2023

Fix microsoft/vcpkg#32522

Currently, the download_files function is only used by binary caching providers (HttpGetBinaryProvider and GHABinaryProvider), so I think it is okay to change the function so that it does not exit with error.

I manually tested following scenarios:

--only-binarycaching server up server down
Without OK Continue with Warn
With OK Exit with Error

I couldn't find the relevant test code. If you let me know, I'll willing to write it.

@lesomnus lesomnus marked this pull request as draft July 24, 2023 16:24
@lesomnus
Copy link
Contributor Author

I will add test about download_files at vcpkg-test/downloads.cpp tomorrow.

@BillyONeal
Copy link
Member

I agree with your analysis on the impact of this for binary caching, but I do not agree with the solution you've chosen here. Just because today download_files is only used by binary caching does not mean that is all it will ever be used for. Moreover, this silences problems that probably should die like curl crashing.

Your bug report is that curl returned a valid exit code indicating a connection error, and we are interpreting that as 'curl crashed'. I agree that response is overblown, but treating real crashes as nothing isn't great either.

Perhaps having an allow list of known curl exit codes that indicate transient network issues should go into the 'retry' bucket?

@lesomnus
Copy link
Contributor Author

lesomnus commented Jul 25, 2023

@BillyONeal I thought that the program termination should be determined by the caller, not the download_files function. However, if curl returns an exit code such as 1 or 3 (unsupported protocol or malformed URL), it indicates a misconfiguration, and the user should be alerted about it. In this case, I agree with allowing the download_files function to terminate the program.

I will modify the code as you suggested: If three retries are attempted due to an exit code from the allowed list, and all of them fail, warning message is printed and response code of value 0 will returned (as in the current PR implementation). Do you have any opinions or suggestions regarding this?

@BillyONeal
Copy link
Member

I thought that the program termination should be determined by the caller, not the download_files function.

Yes, I agree. I'm saying the interface needs to be changed to expose this error, not just eat the error while printing a warning.

I will modify the code as you suggested: If three retries are attempted due to an exit code from the allowed list, and all of them fail, warning message is printed and response code of value 0 will returned (as in the current PR implementation). Do you have any opinions or suggestions regarding this?

I think it needs to be exposed to the caller somehow so it can emit a reasonable message. Perhaps by returning std::vector<ExpectedL<int>> instead of std::vector<int>

@lesomnus
Copy link
Contributor Author

The --retry N flag in curl retries the request N times in case of a transient error. However, the exit code 7 "Failed to connect to host" (microsoft/vcpkg#32522) is not considered as a transient error in curl, and this can be retried using the --retry-connrefused flag. But, retrying in the case of an actual server unavailability consumes significant time. Therefore, I did not add --retry-connrefused flag.

@lesomnus
Copy link
Contributor Author

673dd2f failed the test since GitHub actions runner for ubuntu 20.04 has a lower version of curl (< 7.75.0, which does not support the %{exit_code} variable for --write-out).

I changed to determine errors based on HTTP response codes instead of the exit code. Also, considering the use of a lower version of curl, I assigned the command's exit code for the last error.

@lesomnus lesomnus marked this pull request as ready for review July 29, 2023 11:59
@autoantwort
Copy link
Contributor

But, retrying in the case of an actual server unavailability consumes significant time.

With --retry 3 it's 7 seconds (1 + 2 + 4) which I think is ok.

In general I would vote for an option like --binarycache-hard-errors (See microsoft/vcpkg#28927)

@autoantwort
Copy link
Contributor

I think the upload code has the same problem (exit code != 0 => exit vcpkg)

@xiaozhuai
Copy link

Any progress of this PR?
This is exactly the feature I need.

@BillyONeal
Copy link
Member

Any progress of this PR? This is exactly the feature I need.

As written it breaks Ubuntu 20.04 customers so I don't think we could accept it in that condition

@lesomnus
Copy link
Contributor Author

Any progress of this PR? This is exactly the feature I need.

As written it breaks Ubuntu 20.04 customers so I don't think we could accept it in that condition

My last comment means that I modified it by changing the way errors are determined (in 4daad5e) because my previous modifications failed in Ubuntu 20.04 (in commit 673dd2f).

@JavierMatosD JavierMatosD added the requires:vcpkg-team-review This PR or issue requires someone from the vcpkg team to take a further look. label Oct 9, 2024
@BillyONeal BillyONeal self-assigned this Dec 21, 2024
@BillyONeal
Copy link
Member

Interesting, with old curl or with how we do this today we don't get exit codes for anything in the 'middle'; I thought at least success or failure would be maintained correctly but nope:

image

@BillyONeal
Copy link
Member

Sorry I broke the merge somehow, will fix...

@BillyONeal BillyONeal force-pushed the fix/ignore-http-provider-error branch from c022a1e to 4daad5e Compare December 26, 2024 19:56
Currently, the `download_files` function is only used by binary caching providers (`HttpGetBinaryProvider` and `GHABinaryProvider`), so I think it is okay to change the function so that it does not exit with error.

I manually tested following scenarios:

| **--only-binarycaching** | **server up** | **server down**    |
| ------------------------ | ------------- | ------------------ |
| **Without**              | OK            | Continue with Warn |
| **With**                 | OK            | Exit with Error    |

* Move retries for curl operations into curl itself.
* Added function to parse curl status lines with error messages embedded and tests.
* Add getting exit code and error message for each curl operation, and return those operation results through ExpectedL<int> rather than terminating vcpkg.
* Add test case handling for old curl tested on Ubuntu 20.04.
@BillyONeal BillyONeal force-pushed the fix/ignore-http-provider-error branch from 4daad5e to 15b9a99 Compare December 26, 2024 20:04
@BillyONeal
Copy link
Member

BillyONeal commented Dec 26, 2024

I was unable to get the merge to show up cleanly in GitHub, so I put everything into a squash commit. The SHA before I did this was 4daad5e

I also rewrote the status line parsing bit to avoid adding a dependency on iostreams.

@BillyONeal BillyONeal merged commit 7fd552f into microsoft:main Dec 26, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:vcpkg-team-review This PR or issue requires someone from the vcpkg team to take a further look.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary caching fail is not a build fail
5 participants