etcd docker: curl is work, golang failed for DeadlineExceeded #16868
Unanswered
HanweiLi-cqu
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Hey @HanweiLi-cqu - Thanks for your question. This issue appears to be with your local environment. Below is the reproduce script I ran which worked fine at my end: cat << EOF > docker-compose.yaml
version: "3.5"
services:
etcd:
hostname: etcd
image: bitnami/etcd:3
deploy:
replicas: 1
restart_policy:
condition: on-failure
privileged: true
volumes:
- "./data/:/opt/bitnami/etcd/data"
environment:
- "TZ=Asia/Shanghai"
- "ETCD_NAME=node1"
- "ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380"
- "ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380"
- "ALLOW_NONE_AUTHENTICATION=yes"
- "ETCD_INITIAL_CLUSTER=node1=http://0.0.0.0:2380"
- "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
ports:
- 2379:2379
- 2380:2380
networks:
- etcdnet
networks:
etcdnet:
name: etcdnet
EOF
docker-compose up -d
cat << EOF > main.go
package main
import (
"go.etcd.io/etcd/client/v3"
"log"
"time"
"context"
)
func main() {
cli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:2379"},
DialTimeout: 5 * time.Second,
})
if err != nil {
log.Fatal(err)
} else {
log.Println("successfully connect etcd")
}
defer cli.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
_, err = cli.Put(ctx, "sample_key", "sample_value")
statusRes, err := cli.Status(context.Background(), "localhost:2379") // Waits here indefinitely
if err != nil {
log.Fatal(err)
log.Fatal(statusRes)
}
defer cancel()
if err != nil {
log.Fatal(err)
}
}
EOF
go mod init example.com/example && go mod tidy
go run main.go
etcdctl get sample_key |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
etcd docker deploy on my server. In my computer, curl is work. However, golang failed for DeadlineExceeded. Firewall-cmd strategy was set so that curl could work.
I use curl command as below:
curl -L http://my-server-ip:2379/v3/kv/put -X POST -d '{"key": "bmFtZQ==", "value":"emhhbmdzYW4="}'
and golang code as below:
This code return error:
I've set up a firewall policy, so I don't think there should be a problem with the network, and curl is working.
So I'd like to ask if there is any other problem, or if it's really a problem with my configuration or network
Beta Was this translation helpful? Give feedback.
All reactions