Skip to content
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

rpc: fix RPC client doesn't handle url's without ports #6507

Merged
merged 11 commits into from Jun 14, 2021

Conversation

JayT106
Copy link
Contributor

@JayT106 JayT106 commented May 28, 2021

padding service name as port when URL doesn't have port info, so net.dialer will lookup the default port for the service.

Closes #5407

@JayT106 JayT106 changed the title Fix RPC client doesn't handle url's without ports rpc: Fix RPC client doesn't handle url's without ports May 28, 2021
@JayT106 JayT106 changed the title rpc: Fix RPC client doesn't handle url's without ports rpc: fix RPC client doesn't handle url's without ports May 28, 2021
@codecov
Copy link

codecov bot commented May 28, 2021

Codecov Report

Merging #6507 (44c00ae) into master (007eeb9) will decrease coverage by 4.91%.
The diff coverage is 17.31%.

@@            Coverage Diff             @@
##           master    #6507      +/-   ##
==========================================
- Coverage   65.99%   61.08%   -4.92%     
==========================================
  Files         234      295      +61     
  Lines       20269    27860    +7591     
==========================================
+ Hits        13376    17017    +3641     
- Misses       5825     9131    +3306     
- Partials     1068     1712     +644     
Impacted Files Coverage Δ
abci/client/grpc_client.go 0.00% <0.00%> (ø)
abci/client/local_client.go 0.00% <0.00%> (ø)
abci/types/application.go 0.00% <0.00%> (ø)
abci/types/pubkey.go 0.00% <0.00%> (ø)
abci/types/result.go 23.07% <0.00%> (ø)
abci/types/util.go 0.00% <0.00%> (ø)
cmd/tendermint/commands/gen_node_key.go 0.00% <ø> (ø)
cmd/tendermint/commands/gen_validator.go 18.18% <ø> (+18.18%) ⬆️
cmd/tendermint/commands/init.go 3.27% <ø> (+3.27%) ⬆️
cmd/tendermint/commands/light.go 24.27% <ø> (ø)
... and 426 more

@@ -378,7 +380,13 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error),
}

dialFn := func(proto, addr string) (net.Conn, error) {
return net.Dial(protocol, u.GetDialAddress())
var timeout = 10 * time.Second
if !u.isUnixSocket && strings.LastIndex(u.Host, ":") == -1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of input here and resulting output?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://foo-bar.com -> foo-bar.com:https
http://foo-bar.com -> foo-bar.com:http
unix:///tmp/test -> 'unix:///tmp/test' (because it's UnixSocket)

ref: https://cs.opensource.google/go/go/+/refs/tags/go1.16.4:src/net/ipsock.go;drc=193d5141318d65cea310d995258288bd000d734c;l=248

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why do we need to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixes just try to tackle the issue @marbar3778 posted. We can just close it if we think the current error message is good enough. But the user needs to aware they need to input the URL address with port info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in newParsedURL function.if we do url.Parse with https://foo-bar.com.
We will get url.Scheme = "https", url.Host = "foo-bar.com"
So under this input case, It's not able to connect to the remote due to a missing port.
Therefore I am padding the protocol at the end of the Host, and then the socket will look up the default port for the protocol.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will let @marbar3778 approve this one 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes things a bit easier for when a user is connecting to a URL. What is the norm here? Should the application handle this instead?

rpc/jsonrpc/client/http_json_client.go Outdated Show resolved Hide resolved
@@ -84,3 +84,18 @@ func Test_parsedURL(t *testing.T) {
})
}
}

func TestMakeHTTPDialerURL(t *testing.T) {
remotes := []string{"https://foo-bar.com", "http://foo-bar.com"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to add other kinds of protocols and/or test error cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tychoish what other kinds of protocols we will use in the HTTP client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add some error cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 2 error test cases.

@tessr
Copy link
Contributor

tessr commented Jun 7, 2021

@JayT106 is this ready for another review? @tychoish do you want to re-review?

@cmwaters cmwaters merged commit cb63ab4 into tendermint:master Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC: does not handle url's without ports
6 participants