hxmhlt commented on a change in pull request #482:
URL: https://github.com/apache/dubbo-go/pull/482#discussion_r412801332
##########
File path: protocol/dubbo/pool.go
##########
@@ -50,9 +50,20 @@ type gettyRPCClient struct {
var (
errClientPoolClosed = perrors.New("client pool closed")
+ // for shared tcp connection for same ip and port
+ gettyRPCClients sync.Map
)
func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string)
(*gettyRPCClient, error) {
+
+ if client, ok := gettyRPCClients.Load(addr); ok {
+ cl := client.(*gettyRPCClient)
+ if cl.isAvailable() {
+ return cl, nil
+ }
+ cl.gettyClient.Close()
+ }
Review comment:
Close directly maybe dangerous. May be need lazy close.
##########
File path: protocol/dubbo/pool.go
##########
@@ -63,6 +74,8 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool,
protocol, addr string) (*ge
getty.WithReconnectInterval(pool.rpcClient.conf.ReconnectInterval),
),
}
+ gettyRPCClients.Store(addr, c)
+
Review comment:
Load and Store maybe an atomic operating? So I suggest a double `Load`
check here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]