Skip to content

🐞 [Bug]: Proxy client retries indefinitely on unreachable DNS server #1310

@scottyeager

Description

@scottyeager

I noticed while troubleshooting an issue with the farmerbot that RetryingClient fails to move on from an unreachable DNS server, in the case that multiple DNS servers are specified in resolve.conf. This is in direct contrast to a textbook net/http example program, where the unreachable DNS server is only tried once and the program quickly moves on to a reachable server to complete the request.

Here are the two programs to compare. First the generic example:

// example.go

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	// URL of the webpage to fetch
	url := "https://example.com"

	// Send an HTTP GET request
	response, err := http.Get(url)
	if err != nil {
		fmt.Printf("Error fetching %s: %v\n", url, err)
		return
	}
	defer response.Body.Close() // Ensure the response body is closed

	// Read the response body
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		fmt.Printf("Error reading response body: %v\n", err)
		return
	}

	// Print the response body as a string
	fmt.Println(string(body))
}

Now the example using the proxy client:

// proxy.go

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/client"
)

func main() {
	// Create a new proxy client
	proxyClient := client.NewRetryingClient(client.NewClient("https://gridproxy.grid.tf"))

	ctx := context.Background()

	nodeID := uint32(1)
	node, err := proxyClient.Node(ctx, nodeID)
	if err != nil {
		log.Fatalf("Failed to fetch node %d: %v", nodeID, err)
	}

	// Print node information
	fmt.Printf("Node %d details:\n", nodeID)
	fmt.Printf("  ID: %d\n", node.NodeID)
	fmt.Printf("  Farm ID: %d\n", node.FarmID)
	fmt.Printf("  Twin ID: %d\n", node.TwinID)
	fmt.Printf("  Country: %s\n", node.Country)
	fmt.Printf("  City: %s\n", node.City)
}

Here's a demo comparing the DNS behaviors of the two programs. We simulate an unreachable DNS server by adding a dummy address to resolv.conf:

Image

The proxy client will eventually give up. It never tries the working server further down the list.

Metadata

Metadata

Assignees

Labels

grid-proxybelongs to grid proxy

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions