-
Notifications
You must be signed in to change notification settings - Fork 909
GODRIVER-3092 Fix UNIX socket in URL parsing. #1521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
API Change Report./x/mongo/driver/connstringincompatible changesParse: changed from func(string) (ConnString, error) to func(string) (*ConnString, error) compatible changesConnString.RawHosts: added |
8f63170
to
1af1bb2
Compare
bson/encoder_example_test.go
Outdated
@@ -248,7 +248,7 @@ func ExampleEncoder_IntMinSize() { | |||
panic(err) | |||
} | |||
|
|||
enc, err := bson.NewEncoder(vw) | |||
enc := bson.NewEncoder(vw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the build.
@@ -237,7 +237,6 @@ type ClientOptions struct { | |||
ZstdLevel *int | |||
|
|||
err error | |||
uri string | |||
cs *connstring.ConnString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the uri
so the ConnString.Original
is the single point of truth.
ec75183
to
655c007
Compare
func (u ConnString) String() string { | ||
return u.Original | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ConnString
struct consumes almost 1kb per copy. We should always be passing it by pointer for that reason (including the return value of Parse
and ParseAndValidate
).
} | ||
host, err := url.QueryUnescape(host) | ||
if err != nil { | ||
return fmt.Errorf("invalid host %q: %w", host, err) | ||
return host, fmt.Errorf("invalid host %q: %w", host, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go functions conventionally return the zero value if returning an error. Is there a reason to return host
instead of ""
?
host, err := url.QueryUnescape(host) | ||
if err != nil { | ||
return fmt.Errorf("invalid host %q: %w", host, err) | ||
return host, fmt.Errorf("invalid host %q: %w", host, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url.QueryUnescape
returns empty string on error. As a result, the error returned here will always have an empty host string. What we want instead is the original, invalid host value.
E.g.
unescaped, err := url.QueryUnescape(host)
if err != nil {
return "", fmt.Errorf("error query unescaping host %q: %w", host, err)
mongo/options/clientoptions.go
Outdated
func (c *ClientOptions) GetRawHosts() []string { | ||
if c.cs == nil { | ||
return nil | ||
} | ||
return c.cs.RawHosts | ||
} | ||
|
||
// GetScheme returns the scheme. If ApplyURI was not called during construction, this returns "". | ||
func (c *ClientOptions) GetScheme() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about exposing these values piecemeal in the ClientOptions
API. The pattern isn't sustainable if we need to continue to expose more connection string or other config data to users.
Is there another way to pass the data to topology.New
without having to add methods to ClientOptions
?
63de888
to
31e2a67
Compare
31e2a67
to
b3dc788
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
GODRIVER-3092
Summary
url.Parse()
call.ConnString
Background & Motivation
Add
RawHosts
toConnString
, so we can initialTopology
with scheme and hosts parsed byConnString
from the URI.The
RawHosts
is directly parsed from the URI string before SRV lookup.