mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
internal/controld: connect to API using ipv4 only
Connecting to API using ipv6 sometimes hang at TLS handshake, using ipv4 only so we can fetch the config more reliably. Fixed #53
This commit is contained in:
committed by
Cuong Manh Le
parent
3218b5fac1
commit
45f827a2c5
@@ -70,7 +70,7 @@ func FetchResolverConfig(uid string) (*ResolverConfig, error) {
|
|||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
return Dialer.DialContext(ctx, network, addr)
|
return Dialer.DialContext(ctx, "tcp4", addr)
|
||||||
}
|
}
|
||||||
client := http.Client{
|
client := http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const utilityURL = "https://api.controld.com/utility"
|
const utilityURL = "https://api.controld.com/utility"
|
||||||
@@ -24,7 +25,7 @@ func TestFetchResolverConfig(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
got, err := FetchResolverConfig(tc.uid)
|
got, err := FetchResolverConfig(tc.uid)
|
||||||
assert.False(t, (err != nil) != tc.wantErr)
|
require.False(t, (err != nil) != tc.wantErr, err)
|
||||||
if !tc.wantErr {
|
if !tc.wantErr {
|
||||||
assert.NotEmpty(t, got.DOH)
|
assert.NotEmpty(t, got.DOH)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user