[fix][client] Apply connect and request timeouts to the OAuth2 HTTP requests - #609
Closed
david-streamlio wants to merge 1 commit into
Closed
[fix][client] Apply connect and request timeouts to the OAuth2 HTTP requests#609david-streamlio wants to merge 1 commit into
david-streamlio wants to merge 1 commit into
Conversation
…equests The OAuth2 flows fetched the OpenID discovery document and the token with no timeout: CurlWrapper::Options::timeoutInSeconds defaults to 0, which libcurl reads as "no limit", and CURLOPT_CONNECTTIMEOUT was never set. An issuer that accepts the connection but never replies therefore blocked getAuthData() forever. Add connectTimeoutInSeconds to CurlWrapper::Options (applied as CURLOPT_CONNECTTIMEOUT only when set, so other callers are unaffected) and set both timeouts at the two OAuth2 call sites. The values are configurable through the OAuth2 ParamMap via connect_timeout_seconds (default 10) and request_timeout_seconds (default 30). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
|
Closing this as a duplicate of #606, which covers the same fix and predates this PR. Both add Two small deltas from this PR that might be worth folding into #606:
/cc @RobertIndie — #608 stays open until #606 lands. |
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.
Fixes #608
Motivation
The OAuth2 authentication flows issue two HTTP requests — the OpenID discovery request to
<issuer_url>/.well-known/openid-configurationand the token request to the token endpoint —and neither had any timeout configured.
CurlWrapper::Options::timeoutInSecondsdefaults to0, which libcurl interprets as "nolimit" for
CURLOPT_TIMEOUT, andCURLOPT_CONNECTTIMEOUTwas never set at all. Both OAuth2call sites left the default in place:
fetchTokenEndpoint()passed{}andfetchOauth2Token()only setpostFields.As a result, an issuer that accepts the TCP connection but never replies blocks
Authentication::getAuthData()— and therefore client creation and every subsequentreconnection — forever, with no way for the application to recover.
Modifications
CurlWrapper::OptionsgainsconnectTimeoutInSeconds, applied asCURLOPT_CONNECTTIMEOUTwhen greater than 0. The existing
timeoutInSeconds{0}default is unchanged, so the othercallers of
CurlWrapper::get()keep their current behaviour.Both timeouts are now set at the two OAuth2 call sites.
The values are configurable through the OAuth2
ParamMap, alongsideissuer_url,audienceandscope:connect_timeout_seconds, default10request_timeout_seconds, default30A missing key, or a value that is not a non-negative integer, falls back to the default and
logs a warning.
0is accepted and falls back to libcurl's own defaults. Both keys work forclient_secret_postandtls_client_auth, and are documented ininclude/pulsar/Authentication.h.Drive-by:
CURLOPT_TIMEOUTandCURLOPT_CONNECTTIMEOUTare now passed aslong.curl_easy_setoptis variadic and reads alongfor these options, so passing anintwasundefined behaviour.
Verifying this change
This change added tests and can be verified as follows:
AuthPluginTest.testOauth2UnresponsiveIssuerpoints an OAuth2 flow at a local socket thatis bound and listening but never accepted — the kernel completes the TCP handshake from the
listen backlog, so the client connects and then waits for a response that never arrives. The
test configures
request_timeout_seconds = 2and asserts thatgetAuthData()returnsResultAuthenticationErrorwithin a bounded time instead of hanging. It completes in ~2s;with the timeout removed the same test hangs indefinitely.
AuthPluginTest.testOauth2TimeoutSettingscovers the defaults, explicit values,0, andinvalid values falling back to the defaults.
Ran locally with
--gtest_filter=*Oauth2*: 11 of 12 pass. The remaining failure,testOauth2Failure, requires a broker onlocalhost:6650and fails identically onmain.Documentation
doc-required(The two new
connect_timeout_seconds/request_timeout_secondsparameters should be addedto the OAuth2 section of the C++ client docs on the website. The Doxygen comments in
include/pulsar/Authentication.hare updated in this PR.)🤖 Generated with Claude Code