write/service: handle a nil URL from url.Parse without panicking#427
Open
c-tonneslan wants to merge 1 commit into
Open
write/service: handle a nil URL from url.Parse without panicking#427c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
NewClient accepts any string for serverURL and only stores it; a
malformed value like a bare host:port ("192.168.1.104:8086") makes
url.Parse return nil and an error. NewService discarded that error
and immediately called u.Parse("write") on the nil URL, taking the
whole program down with a nil pointer dereference.
Fall back to building the write URL by string concatenation when
url.Parse fails. The bad address still surfaces later when the HTTP
request is dispatched, just as a regular network/HTTP error instead
of a panic.
Fixes influxdata#422
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #427 +/- ##
=======================================
Coverage 92.99% 92.99%
=======================================
Files 25 25
Lines 2326 2326
=======================================
Hits 2163 2163
Misses 123 123
Partials 40 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 #422.
NewClientaccepts any string forserverURLand only stores it. A malformed value like a bare host:port (192.168.1.104:8086) makesurl.Parsereturn(nil, err).internal/write.NewServicediscards that error and immediately callsu.Parse("write")on the nil URL, panicking on firstWriteAPIBlockinguse.Stack trace from the repro in the issue:
Fall back to building the write URL by string concatenation when
url.Parsefails. The bad address still surfaces later when the HTTP request is dispatched, just as a regular network/HTTP error instead of a panic.Added a regression test that constructs
NewServicewith the broken URL from the issue.Fixes #422