rpcxio / rpcx-etcd

etcd plugin for rpcx
Apache License 2.0
30 stars 24 forks source link

When I watch a directory that does not exist, EtcdV3Discovery immediately exits. #11

Closed eaglc closed 3 years ago

eaglc commented 3 years ago

When I watch a directory that does not exist, EtcdV3Discovery immediately exits. I want to know whether this logic reasonable? In this case, we must strictly ensure the startup sequence of the service or persist the directory to etcd in advance. But in my application scenario, I Don't want to care about these.


func (s *EtcdV3) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
    watchCh := make(chan []*store.KVPair)

    go func() {
        defer close(watchCh)

        list, err := s.List(directory)
        if err != nil  {
                       // exist here.
            return
        }

        watchCh <- list
                ...
        }
        ...
}

tks

smallnest commented 3 years ago

For microservices, you can access those services only those services are registered. So it is a reasonable.

eaglc commented 3 years ago

For microservices, you can access those services only those services are registered. So it is a reasonable.

I agree with this.

The resulting problems are: The function NewEtcdV3Discovery return with success.

client/etcdv3_discovery.go line:59

then the d.watch goroutine exits (due to the directory does not exist) and my client cant not perceive it.

store/etcdv3/etcdv3.go line:294

As a result, my client kept running, but it can no longer find the service even after the service is registered.

Is there a contradiction here?

smallnest commented 3 years ago

It is a problem. This plugin must check existence and return an error if the watched path doesn't exist

smallnest commented 3 years ago

image

smallnest commented 3 years ago

Here we should return the error if err == store.ErrKeyNotFound.

eaglc commented 3 years ago

Great! Look forward to fix soon.

thk