Aetherance commented on code in PR #3086:
URL: https://github.com/apache/dubbo-go/pull/3086#discussion_r2632184322
##########
protocol/triple/client.go:
##########
@@ -57,30 +57,57 @@ const (
// callUnary, callClientStream, callServerStream, callBidiStream.
// A Reference has a clientManager.
type clientManager struct {
- isIDL bool
- // triple_protocol clients, key is method name
- triClients map[string]*tri.Client
+ isIDL bool
+ triGuard *sync.RWMutex
+ // triple_protocol clients
+ triClients *TriClientPool
}
// TODO: code a triple client between clientManager and triple_protocol client
// TODO: write a NewClient for triple client
func (cm *clientManager) getClient(method string) (*tri.Client, error) {
- triClient, ok := cm.triClients[method]
- if !ok {
+ cm.triGuard.RLock()
+ if cm.triClients == nil {
+ cm.triGuard.RUnlock()
+ return nil, fmt.Errorf("no client pool found for method: %s",
method)
+ }
+ triClient, err := cm.triClients.Get(constant.DefaultClientGetTimeout)
+ cm.triGuard.RUnlock()
+ if triClient == nil {
+ return nil, fmt.Errorf("missing triple client for method: %s",
method)
+ }
+ // Wait up to defaultClientGetTimeout for a pooled client; if none
becomes available we return the
+ // fallback client and record a timeout which is used to drive
autoscaling.
+ if err != nil {
return nil, fmt.Errorf("missing triple client for method: %s",
method)
}
return triClient, nil
}
+func (cm *clientManager) putClient(method string, c *tri.Client) {
+ if c == nil {
+ return
+ }
+
+ if cm.triClients == nil {
Review Comment:
确实是我的问题,已修复
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]