在这种情况下:
我有以下恐慌:
panic: close of closed channel
goroutine 2849 [running]:
github.com/samuel/go-zookeeper/zk.(*Conn).Close(0xc420795180)
github.com/samuel/go-zookeeper/zk/conn.go:253 47
github.com/curator-go/curator.(*handleHolder).internalClose(0xc4203058f0, 0xc420302470, 0x0)
github.com/curator-go/curator/state.go:136 +0x8d
github.com/curator-go/curator.(*handleHolder).closeAndReset(0xc4203058f0, 0xc42587cd00, 0x1e)
github.com/curator-go/curator/state.go:122 +0x2f
github.com/curator-go/curator.(*connectionState).reset(0xc420302420, 0x1b71d87, 0xf)
github.com/curator-go/curator/state.go:234 +0x55
github.com/curator-go/curator.(*connectionState).handleExpiredSession(0xc420302420)
github.com/curator-go/curator/state.go:351 +0xd9
github.com/curator-go/curator.(*connectionState).checkState(0xc420302420, 0xffffff90, 0x0, 0x0, 0xc425ed2600, 0xed0e5250a)
github.com/curator-go/curator/state.go:318 +0x9c
github.com/curator-go/curator.(*connectionState).process(0xc420302420, 0xc425ed2680)
github.com/curator-go/curator/state.go:299 +0x16d
created by github.com/curator-go/curator.(*Watchers).Fire
github.com/curator-go/curator/watcher.go:64 +0x96以下是详细的事件顺序:
s.ReregisterAll() -> Conn() -> checkTimeout() -> reset (bc 1分钟已经过去) -> closeAndReset() -> conn.Close() ,可以阻塞第二个zk.StateExpired (zk集群发送这个bc,它认为这个客户端是死的,因为它没有在2.) -> reset -> closeAndReset() -> conn.Close(),这引起了恐慌,因为conn.Close()已经关闭了连接的c.shouldQuit通道,而s.zooKeeper.getZookeeperConnection从来没有被goroutine A调用,因为它阻塞了第二个,所以没有新的连接。我尝试过的一个简单的解决方案就是在reset上使用互斥,但现在我得到的helper.GetConnectionString()等于空字符串。什么是最好的方法,以避免这种崩溃,并试图进入一个良好的状态时,客户端失去,然后恢复网络连接?修复是否应该在Github.com/samuel/go-zoo牧民的实现中,不让您关闭已经关闭的连接?
(我已将这个问题提交给这里,但该项目似乎缺乏讨论,因此我要求如此。)
发布于 2018-02-19 20:33:34
zk.Conn有一个State()方法,它返回一个枚举"State",这是以下内容之一:
type State int32
const (
StateUnknown State = -1
StateDisconnected State = 0
StateConnecting State = 1
StateAuthFailed State = 4
StateConnectedReadOnly State = 5
StateSaslAuthenticated State = 6
StateExpired State = -112
StateConnected = State(100)
StateHasSession = State(101)
)当goroutine B调用conn.Close()时,"conn“在什么状态?
一个可能的解决方案是向goroutine添加一个开关,如果您使用的是conn.Close(),则不调用conn.StateConnecting ()。
https://stackoverflow.com/questions/44856087
复制相似问题