rpcxio / rpcx-gateway

http gateway for rpcx services. Clients in any programming languages can call them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deadlock if rpcx-service is not registed in consul

jeek120 opened this issue · comments

commented

followed in gateway.go

g.mu.Lock()
if g.xclients[servicePath] == nil {
	g.xclients[servicePath] = client.NewXClient(servicePath, g.FailMode, g.SelectMode, g.serviceDiscovery.Clone(servicePath), g.Option)
}
xc = g.xclients[servicePath]
g.mu.Unlock()

cannot run g.mu.Unlock() if rpcx-service is not registed in consul, because call panic in consul_disconvery.go
you could add defer before g.mu.Unlock() .

commented

I fixed the bug by followed code:

g.mu.Lock()
if g.xclients[servicePath] == nil {
	defer func() {
		//if err := recover(); err != nil {
			if !is_unlock {
				g.mu.Unlock()
				//panic(err)
			}
		//}
	}()
	g.xclients[servicePath] = client.NewXClient(servicePath, g.FailMode, g.SelectMode, g.serviceDiscovery.Clone(servicePath), g.Option)

}
xc = g.xclients[servicePath]
g.mu.Unlock()
is_unlock = true

fixed. Thanks