Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

EventNodeDeleted is missing #24

Closed
Vanderpool opened this issue Mar 6, 2014 · 1 comment
Closed

EventNodeDeleted is missing #24

Vanderpool opened this issue Mar 6, 2014 · 1 comment

Comments

@Vanderpool
Copy link

According to zookeeper document, if ChildrenWatcher is set on a node, when this node deleted, EventNodeDeleted should be received on the watcher. But this event is only sent to Conn.eventChan.

example code:

package main

import (
        "fmt"
        "github.com/samuel/go-zookeeper/zk"
        "time"
)

func main() {
        c, zkChan, err := zk.Connect([]string{"127.0.0.1"}, time.Second) //*10)
        if err != nil {
                panic(err)
        }
        children, stat, wCh, err := c.ChildrenW("/foo")
        if err != nil {
                panic(err)
        }
        fmt.Printf("%+v %+v\n", children, stat)
        for {
                select {
                case e := <-wCh:
                        fmt.Printf("get event from watcher: %+v\n", e)
                case e := <-zkChan:
                        fmt.Printf("get event from session: %+v\n", e)
                }
        }
}

output:

go run watcher.go 
[] &{Czxid:25769803778 Mzxid:25769803778 Ctime:1394091427992 Mtime:1394091427992 Version:0 Cversion:0 Aversion:0 EphemeralOwner:0 DataLength:2 NumChildren:0 Pzxid:25769803778}
get event from session: {Type:EventSession State:StateConnecting Path: Err:<nil>}
get event from session: {Type:EventSession State:StateConnected Path: Err:<nil>}
get event from session: {Type:EventSession State:StateHasSession Path: Err:<nil>}
get event from session: {Type:EventNodeDeleted State:StateSyncConnected Path:/foo Err:<nil>}
^Cexit status 2

seems a minor modification is needed on conn.go:

@@ -497,7 +497,7 @@ func (c *Conn) recvLoop(conn net.Conn) error {
            case EventNodeCreated:
                wTypes = append(wTypes, watchTypeExist)
            case EventNodeDeleted, EventNodeDataChanged:
 -              wTypes = append(wTypes, watchTypeExist, watchTypeData)
 +              wTypes = append(wTypes, watchTypeExist, watchTypeData, watchTypeChild)
            case EventNodeChildrenChanged:
                wTypes = append(wTypes, watchTypeChild)
            }

@samuel
Copy link
Owner

samuel commented Mar 12, 2014

Thanks for the report. Fixed in master: 8edc763

@samuel samuel closed this as completed Mar 12, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants