samuel / go-zookeeper

Native ZooKeeper client for Go. This project is no longer maintained. Please use https://github.com/go-zookeeper/zk instead.
BSD 3-Clause "New" or "Revised" License
1.64k stars 672 forks source link

data race in conn.go #178

Closed teou closed 5 years ago

teou commented 7 years ago

hi guys data race is detected when we run go-zookeeper on : go build -race

WARNING: DATA RACE Write at : github.com/samuel/go-zookeeper/zk.(*Conn).recvLoop() github.com/samuel/go-zookeeper/zk/conn.go:820

Previous read at : github.com/samuel/go-zookeeper/zk.(*Conn).sendSetWatches() github.com/samuel/go-zookeeper/zk/conn.go:567

maybe Conn.lastZxid needs to be lock protected?

adamdecaf commented 5 years ago

I can't reproduce anymore. Close?

$ go version
go version go1.11 linux/amd64

$ git log -n1
commit c4fab1ac1bec58281ad0667dc3f0907a9476ac47
Author: Samuel Stauffer <samuel@descolada.com>
Date:   Tue Jan 30 11:37:22 2018 -0800

    Fix race conditions in t test

$ go build -race .
$ 
huaz836 commented 3 years ago

Reproduce this case when test my app with go race. The log:

2021/06/21 15:21:58 recv loop terminated: err=failed to read from connection: read tcp 192.168.1.101:56952->192.168.1.101:2181: i/o timeout
2021/06/21 15:21:58 recv loop terminated: err=failed to read from connection: read tcp 192.168.1.101:56976->192.168.1.101:2181: i/o timeout
==================
WARNING: DATA RACE
Write at 0x00c0001ee000 by goroutine 77:
  github.com/samuel/go-zookeeper/zk.(*Conn).recvLoop()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:910 +0xc4c
  github.com/samuel/go-zookeeper/zk.(*Conn).loop.func2()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:521 +0x2f1

Previous read at 0x00c0001ee000 by goroutine 8:
  github.com/samuel/go-zookeeper/zk.(*Conn).sendSetWatches()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:637 +0x472
  github.com/samuel/go-zookeeper/zk.(*Conn).loop()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:535 +0x5a4
  github.com/samuel/go-zookeeper/zk.Connect.func1()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:223 +0x3c

Goroutine 77 (running) created at:
  github.com/samuel/go-zookeeper/zk.(*Conn).loop()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:516 +0x576
  github.com/samuel/go-zookeeper/zk.Connect.func1()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:223 +0x3c

Goroutine 8 (running) created at:
  github.com/samuel/go-zookeeper/zk.Connect()
      /gopath/src/github.com/samuel/go-zookeeper/zk/conn.go:222 +0x8c6

     // ... more application call stack
     // call like this
     // zkConn, chanConnect, err := zk.Connect([]string{zkAddr}, time.Second*30, zk.WithLogInfo(false))
==================

centos 7 go 1.16.2 zookeeper 3.6.2