-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
66513: sqlproxyccl: fix DNS resolution logic in backendLookupAddr r=andy-kimball a=jaylim-crl Previously, we were using net.LookupAddr in backendLookupAddr, but that was incorrect since [net.LookupAddr](https://golang.org/pkg/net/#LookupAddr) is meant to perform a reverse lookup. The intention was to resolve the address (e.g. foo-bar-2-0.cockroachdb:80) to an IP. This patch fixes that by using base.LookupAddr instead, which will resolve the given address/host to an IP address. Note that the tests added are not exhaustive since the code in backendLookupAddr will eventually go away. Release note: None Co-authored-by: Jay Lim <[email protected]>
- Loading branch information
Showing
6 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package sqlproxyccl | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
) | ||
|
||
func TestBackendLookupAddr(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
ctx := context.Background() | ||
|
||
// Note that this list isn't exhaustive. We only cover the common cases. | ||
// backendLookupAddr is only temporary, and will go away soon. | ||
testData := []struct { | ||
in string | ||
expected string | ||
expectedErr string | ||
}{ | ||
// Invalid routing rules. | ||
{"foobar", "", "missing port in address"}, | ||
{"foobar:", "", "no port was provided for 'foobar:'"}, | ||
{":80", "", "no host was provided for ':80'"}, | ||
{":", "", "no host was provided for ':'"}, | ||
|
||
// Invalid hosts. | ||
{"nonexistent.example.com:26257", "", "no such host"}, | ||
{"333.333.333.333:26257", "", "no such host"}, | ||
|
||
// Valid hosts. | ||
{"127.0.0.1:80", "127.0.0.1:80", ""}, | ||
{"localhost:80", "127.0.0.1:80", ""}, | ||
} | ||
for i, test := range testData { | ||
t.Run(fmt.Sprintf("%d/%s", i, test.in), func(t *testing.T) { | ||
addr, err := backendLookupAddr(ctx, test.in) | ||
if err != nil { | ||
if !testutils.IsError(err, test.expectedErr) { | ||
t.Fatalf("expected error %q, got %v", test.expectedErr, err) | ||
} | ||
return | ||
} | ||
if test.expectedErr != "" { | ||
t.Fatalf("expected error %q, got success", test.expectedErr) | ||
} | ||
if addr != test.expected { | ||
t.Fatalf("expected %q,\ngot %q", test.expected, addr) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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