Improve hfile_s3.c error handling#2036
Merged
Merged
Conversation
Libcurl API functions mostly do not set errno, so set it explicitly based on libcurl API error codes. Copy easy_errno() from hfile_libcurl.c, alongside the previously copied http_status_errno(). Also preserve errno in s3_read_open()/s3_write_open()'s error cleanup. Otherwise it will often be changed to EAGAIN by curl_easy_cleanup(), which is called during cleanup_local(). curl_global_init() always returns CURLE_FAILED_INIT on error, so simply translate that never-happens into a suitably catastrophic errno value. Signed-off-by: John Marshall <jmarshall@hey.com>
jmarshall
commented
Jun 16, 2026
Comment on lines
+2596
to
+2597
| // Set a suitably catastrophic error code | ||
| errno = ENETDOWN; |
Member
Author
There was a problem hiding this comment.
curl_global_init() always returns CURLE_FAILED_INIT on error, so simply translate that never-happens into a suitably catastrophic errno value.
jmarshall
commented
Jun 16, 2026
| cret = curl_easy_getinfo(fp->curl, CURLINFO_RESPONSE_CODE, &response_code); | ||
|
|
||
| if (cret != CURLE_OK || response_code > 200) { | ||
| if (cret != CURLE_OK) { |
Member
Author
There was a problem hiding this comment.
In the unlikely event curl_easy_getinfo() fails, response_code will usually not have been written to. So separating these cases avoids reading an uninitialised variable in http_status_errno(response_code) below.
Member
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The rewritten S3 backend does not translate libcurl error values into errno values; in some circumstances it returns an error indication but does not set
errnoat all, leaving it set to whatever it was set to previously. So for example a malformatted URL results in a spurious ENOENT error message:This led to a bioconda package build test failure (bioconda/bioconda-recipes#64884):
because the test was written to validate the expected particular
errnovalue that the libcurl backend produces. This particular test has since been rewritten in a more robust way, but nonetheless hfile_s3.c should enable meaningful error messages.Also requests for buckets which you don't have permission to access or non-existent buckets produce unhelpful errors:
With
-vvvvyou can see thaterrnois being set appropriately from the 403 or 404 response, but it is overwritten with a spurious EAGAINerrnovalue before it is returned to the caller.Hence this PR:
Libcurl API functions mostly do not set
errno, so set it explicitly based on libcurl API error codes. Copyeasy_errno()from hfile_libcurl.c, alongside the previously copiedhttp_status_errno().Also preserve
errnoins3_read_open()/s3_write_open()'s error cleanup. Otherwise it will often be changed to EAGAIN bycurl_easy_cleanup(), which is called duringcleanup_local().