projectcalico / calico

Cloud native networking and network security
https://docs.tigera.io/calico/latest/about/
Apache License 2.0
6.02k stars 1.34k forks source link

calico client hang up when set wrong etcd endponits address. #5201

Open nayihz opened 3 years ago

nayihz commented 3 years ago

Expected Behavior

calico client will return an error if etcd endpoints address is wrong.

Current Behavior

The calico client will hang up by set a wrong etcd endpoints address deliberately. And you will find that this connetion will be reset after 5 times retry. image

Possible Solution

Steps to Reproduce (for bugs)

func main()  {
        os.Setenv("ETCD_CA_CERT_FILE", "/etc/calico/certs/etcd-ca")
    os.Setenv("ETCD_CERT_FILE", "/etc/calico/certs/etcd-cert")
         // set a wrong endpoints address. The ip doesn't exist.
    os.Setenv("ETCD_ENDPOINTS", "https://10.0.0.1:2379")
    os.Setenv("ETCD_KEY_FILE", "/etc/calico/certs/etcd-key")
         // set other environment variables.....
    fmt.Println("calicoClient init begin...")
    // it will not return error
        // set other environment variables 
    calicoClient, err := calicoclient.NewFromEnv()
    if err != nil {
        return nil, err
    }
    fmt.Println("calicoClient init end...")

    calicoNodes, err := calicoClient.Nodes().List(context.TODO(), options.ListOptions{})
    if err != nil {
        return nil, err
    }
    fmt.Println("calicoClient get node end...")
}

this process will hang up after print 'calicoClient init end...'

Context

Your Environment

nayihz commented 3 years ago

It seems that here is a timeout parameter for etcd client. But in fact it didn't take effect. https://github.com/projectcalico/libcalico-go/blob/9bf530a83eda619e8c8e1b57dd347b2a3bc9ac5e/lib/backend/etcdv3/etcdv3.go#L119