[Ruby] Make connection failures visible with generated Ruby SDKs #3640
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.
Make HTTP connection failures (e.g. timeouts and TLS verification failures) visible.
I initially started out by filing an issue before figuring out how I could actually resolve this. I pasted the relevant parts of that issue below.
(For what it's worth, I discovered this while updating our SDK to use more up-to-date templates. Here's the branch I'm working on if it makes things easier.)
Current behavior
To reproduce the issue of connection timeout:
I modified this section of code slightly to see how I could resolve that above issue. It looks like this:
And for some reason, it will always pick the second branch and give out an empty error message.
To reproduce the second issue (TLS verification), using above modification:
There is no obvious indication of what went wrong.
[1]:
/usr/local/opt/openssl/bin/openssl s_server -accept 9876 -cert ../server.cert -key ../server.key -WWW(using Homebrewed OpenSSL because the OS X-provided OpenSSL is old and deprecated and supports effectively no modern TLS protocols)Modified behavior from this pull request
Disconnected from network:
TLS verification:
Follow-up question
I'm curious about why we chose to use Typhoeus as the underlying HTTP library. I spoke with a few Rubyist colleagues here, and here's how the Slack conversation turned out (my personal expressed opinions might not be fair because I haven't used the library much):
I did a quick search and it looks like the generated SDK only uses Typhoeus via
Typhoeus::Request.new. It don't use any of that fancy job queuing stuff likeTyphoeus::Hydra. As for why I think Typhoeus's interface is awful, it's pretty much because I had to make this fix: the library seems opinionated about not raising errors, so you have to be very explicit about handling HTTP errors or else they'll pretty much get dropped to the floor.