Copilot commented on code in PR #3757:
URL: https://github.com/apache/dubbo-go/pull/3757#discussion_r4226475034


##########
client/timeout_precedence_test.go:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package client
+
+import (
+       "testing"
+       "time"
+)
+
+import (
+       "github.com/stretchr/testify/require"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/cluster/cluster"
+       "dubbo.apache.org/dubbo-go/v3/cluster/directory"
+       "dubbo.apache.org/dubbo-go/v3/common"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
+       "dubbo.apache.org/dubbo-go/v3/common/extension"
+       "dubbo.apache.org/dubbo-go/v3/global"
+       "dubbo.apache.org/dubbo-go/v3/protocol/base"
+)
+
+type timeoutCaptureProtocol struct{ captured *common.URL }
+
+func (p *timeoutCaptureProtocol) Export(base.Invoker) base.Exporter { return 
nil }
+func (p *timeoutCaptureProtocol) Destroy()                          {}
+func (p *timeoutCaptureProtocol) Refer(u *common.URL) base.Invoker {
+       p.captured = u
+       return base.NewBaseInvoker(u)
+}
+
+type timeoutCaptureCluster struct{}
+
+func (timeoutCaptureCluster) Join(d directory.Directory) base.Invoker {
+       return base.NewBaseInvoker(d.GetURL())
+}
+
+func TestReferenceTimeoutPrecedence(t *testing.T) {
+       tests := []struct {
+               name string
+               opts []ReferenceOption
+               want string
+       }{
+               {"reference timeout wins over consumer", 
[]ReferenceOption{WithRequestTimeout(500 * time.Millisecond)}, "500ms"},
+               {"consumer timeout is the fallback", nil, "3s"},
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       p := &timeoutCaptureProtocol{}
+                       extension.SetProtocol("timeout-precedence", func() 
base.Protocol { return p })

Review Comment:
   This process-global registration retains the closure capturing `p` after the 
subtest finishes. Unregister it during cleanup so later tests do not inherit 
stale protocol state; `registerGenericResultProtocol` uses the same cleanup 
pattern in client/client_test.go:89-97.



##########
client/action.go:
##########
@@ -126,6 +126,13 @@ func (refOpts *ReferenceOptions) refer(srv 
common.RPCService, info *ClientInfo)
                ref.Loadbalance = constant.LoadBalanceKeyP2C
        }
 
+       // The reference-level timeout (already in getURLMap) takes precedence 
over the consumer-level one.
+       // TODO: remove consumer timeout fallback after old config removed
+       timeout := ref.RequestTimeout
+       if len(timeout) == 0 {
+               timeout = refOpts.Consumer.RequestTimeout
+       }

Review Comment:
   `ref` is the client's shared `overallReference`: `Client.dial` passes that 
pointer via `setReference` (client/client.go:208-224), and `WithRequestTimeout` 
mutates it. After one `Dial(..., WithRequestTimeout(500*time.Millisecond))`, a 
later dial without a reference timeout still sees `ref.RequestTimeout == 
"500ms"`, so this new precedence logic makes the first reference's timeout leak 
into every subsequent reference instead of falling back to the consumer 
timeout. Clone `overallReference` for each dial before applying reference 
options, and cover two sequential dials in the regression test.



-- 
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]

Reply via email to