diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 616eb8297..8d753f004 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -126,5 +126,6 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi - [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash) - [blockchain/v1] [\#5701](https://github.com/tendermint/tendermint/pull/5701) Handle peers without blocks (@melekes) - [blockchain/v1] \#5711 Fix deadlock (@melekes) -- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (@cmwaters) +- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (cmwaters) +- [rpc] \#6507 fix RPC client doesn't handle url's without ports (@JayT106) - [statesync] \#6463 Adds Reverse Sync feature to fetch historical light blocks after state sync in order to verify any evidence (@cmwaters) diff --git a/rpc/jsonrpc/client/http_json_client.go b/rpc/jsonrpc/client/http_json_client.go index 67cc79e6e..71c00137b 100644 --- a/rpc/jsonrpc/client/http_json_client.go +++ b/rpc/jsonrpc/client/http_json_client.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "strings" + "time" tmsync "github.com/tendermint/tendermint/internal/libs/sync" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" @@ -370,6 +371,7 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error), } protocol := u.Scheme + padding := u.Scheme // accept http(s) as an alias for tcp switch protocol { @@ -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 { + u.Host = fmt.Sprintf("%s:%s", u.Host, padding) + return net.DialTimeout(protocol, u.GetDialAddress(), timeout) + } + + return net.DialTimeout(protocol, u.GetDialAddress(), timeout) } return dialFn, nil diff --git a/rpc/jsonrpc/client/http_json_client_test.go b/rpc/jsonrpc/client/http_json_client_test.go index 4b82ff1eb..5a03af512 100644 --- a/rpc/jsonrpc/client/http_json_client_test.go +++ b/rpc/jsonrpc/client/http_json_client_test.go @@ -84,3 +84,31 @@ func Test_parsedURL(t *testing.T) { }) } } + +func TestMakeHTTPDialerURL(t *testing.T) { + remotes := []string{"https://foo-bar.com", "http://foo-bar.com"} + + for _, remote := range remotes { + u, err := newParsedURL(remote) + require.NoError(t, err) + dialFn, err := makeHTTPDialer(remote) + require.Nil(t, err) + + addr, err := dialFn(u.Scheme, u.GetHostWithPath()) + require.NoError(t, err) + require.NotNil(t, addr) + } + + errorURLs := []string{"tcp://foo-bar.com", "ftp://foo-bar.com"} + + for _, errorURL := range errorURLs { + u, err := newParsedURL(errorURL) + require.NoError(t, err) + dialFn, err := makeHTTPDialer(errorURL) + require.Nil(t, err) + + addr, err := dialFn(u.Scheme, u.GetHostWithPath()) + require.Error(t, err) + require.Nil(t, addr) + } +}