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

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

Open
scottyeager opened this issue Jan 21, 2025 · 0 comments
Open
Labels
grid-proxy belongs to grid proxy
Milestone

Comments

@scottyeager
Copy link

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.

@rawdaGastan rawdaGastan added the grid-proxy belongs to grid proxy label Jan 26, 2025
@rawdaGastan rawdaGastan added this to the v0.17.x milestone Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grid-proxy belongs to grid proxy
Projects
None yet
Development

No branches or pull requests

2 participants