Fix panic in InitThriftClient when endpoint URL is malformed#394
Open
gretasharoyan wants to merge 1 commit into
Open
Fix panic in InitThriftClient when endpoint URL is malformed#394gretasharoyan wants to merge 1 commit into
gretasharoyan wants to merge 1 commit into
Conversation
8da3b03 to
1740211
Compare
Signed-off-by: Greta Sharoyan <greta@sigmacomputing.com>
1740211 to
51e4fa7
Compare
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.
This surfaces as:
Root cause
In
internal/client/client.go, the HTTP transport path type-asserts the transport before checking the error returned bythrift.NewTHttpClientWithOptions:NewTHttpClientWithOptionsreturns a nilTTransportwhenurl.Parse(endpoint)fails (e.g. a host or HTTP path containing a control character or an invalid%-escape). Asserting a nilTTransportto*thrift.THttpClientpanics, so the existingerrcheck below theswitchis never reached.Because the transport is initialized lazily on the first connection (
connector.Connect→InitThriftClient), this surfaces as a crash while acquiring a connection rather than a returned error.Fix
Move the error check to immediately after
NewTHttpClientWithOptions, before the type assertion. The now-unreachable post-switcherror check is removed; the sameErrInvalidURLerror is returned as before, without panicking.Testing
Added
TestInitThriftClientMalformedEndpointDoesNotPanic, which builds a config whose HTTP path passesToEndpointURL's non-empty validation but failsurl.Parse, and assertsInitThriftClientreturns an error instead of panicking. Verified the test fails (panics) without the fix and passes with it.go vetandgofmtare clean and the fullinternal/clientpackage tests pass.