Skip to content
Snippets Groups Projects
Commit 6bcd1ec4 authored by wangwx's avatar wangwx
Browse files

try to fix provider can't find error

parent 6553c224
No related branches found
No related tags found
No related merge requests found
......@@ -196,10 +196,13 @@ func (di *DubboInvoker) Destroy() {
di.BaseInvoker.Destroy()
client := di.getClient()
if client != nil {
exchangeClientMap.Delete(di.GetUrl().Location)
client.DecreaseActiveNumber()
di.setClient(nil)
if client.GetActiveNumber() == 0 {
exchangeClientMap.Delete(di.GetUrl().Location)
client.Close()
}
}
})
}
......
......@@ -215,7 +215,9 @@ func getExchangeClient(url *common.URL) *remoting.ExchangeClient {
if clientTmp == nil {
return nil
}
return clientTmp.(*remoting.ExchangeClient)
exchangeClient := clientTmp.(*remoting.ExchangeClient)
exchangeClient.IncreaseActiveNumber()
return exchangeClient
}
// rebuildCtx rebuild the context by attachment.
......
......@@ -18,6 +18,7 @@ package remoting
import (
"errors"
"sync/atomic"
"time"
)
......@@ -51,6 +52,8 @@ type ExchangeClient struct {
client Client
// the tag for init.
init bool
// the number of service using the exchangeClient
activeNum uint32
}
// create ExchangeClient
......@@ -59,6 +62,7 @@ func NewExchangeClient(url *common.URL, client Client, connectTimeout time.Durat
ConnectTimeout: connectTimeout,
address: url.Location,
client: client,
activeNum: 0,
}
client.SetExchangeClient(exchangeClient)
if !lazyInit {
......@@ -66,7 +70,7 @@ func NewExchangeClient(url *common.URL, client Client, connectTimeout time.Durat
return nil
}
}
exchangeClient.IncreaseActiveNumber()
return exchangeClient
}
......@@ -87,6 +91,21 @@ func (cl *ExchangeClient) doInit(url *common.URL) error {
return nil
}
// increase number of service using client
func (client *ExchangeClient) IncreaseActiveNumber() {
atomic.AddUint32(&client.activeNum, 1)
}
// decrease number of service using client
func (client *ExchangeClient) DecreaseActiveNumber() {
atomic.AddUint32(&client.activeNum, ^uint32(0))
}
// decrease number of service using client
func (client *ExchangeClient) GetActiveNumber() uint32 {
atomic.LoadUint32(&client.activeNum)
}
// two way request
func (client *ExchangeClient) Request(invocation *protocol.Invocation, url *common.URL, timeout time.Duration,
result *protocol.RPCResult) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment