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

can not get any output when connect to etcd #10791

Closed
maplessssy opened this issue Jun 5, 2019 · 7 comments
Closed

can not get any output when connect to etcd #10791

maplessssy opened this issue Jun 5, 2019 · 7 comments

Comments

@maplessssy
Copy link

maplessssy commented Jun 5, 2019

etcd version: 3.3.10
when etcd is not running, Why is this code without any output?
please help me, thanks

here is my code:

package main

import (
	"context"
	"fmt"
	"go.etcd.io/etcd/clientv3"
	"time"
)

func main() {
	fmt.Println(time.Now().Format("15:04"))
	client, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"localhost:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		fmt.Println("connect etcd err")
		fmt.Println(err)
	}
	fmt.Println("begin watch")
	rch := client.Watch(context.Background(), "/test/lee", clientv3.WithPrefix())
	for resp := range rch {
		for _, ev := range resp.Events {
			fmt.Println(ev)
		}
	}
	defer client.Close()
}
@maplessssy
Copy link
Author

maplessssy commented Jun 5, 2019

here is output:
image

@hexfusion
Copy link
Contributor

hexfusion commented Jun 6, 2019

Are you sure etcd is not running?

$ ss -ltn | grep 2379
$ ./etcd-test 
13:15
connect etcd err
dial tcp [::1]:2379: connect: connection refused
begin watch
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x8d1e18]

goroutine 1 [running]:
main.main()
	etcd-test/main.go:22 +0x248

@jingyih
Copy link
Contributor

jingyih commented Jun 6, 2019

What is the expected output? There is no key value change after the watch is created, therefore watch channel will not receive any event. To receive events of previous key value changes, specify the start revision via option Clientv3.WithRev().

@maplessssy
Copy link
Author

Are you sure etcd is not running?

$ ss -ltn | grep 2379
$ ./etcd-test 
13:15
connect etcd err
dial tcp [::1]:2379: connect: connection refused
begin watch
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x8d1e18]

goroutine 1 [running]:
main.main()
	etcd-test/main.go:22 +0x248

I'm sure.
image

@maplessssy
Copy link
Author

Is it because of the virtual machine environment?
I use vagrant + virtualBox

@gsxhnd
Copy link

gsxhnd commented Oct 19, 2019

resolve: #9877 (comment)

@stale
Copy link

stale bot commented Apr 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants