AlexStocks commented on code in PR #1:
URL: https://github.com/apache/dubbo-net/pull/1#discussion_r4431089111


##########
DubboService/TripleDubboActuatorSuite.cs:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+using DubboNet.Clients.DataModle;
+using DubboNet.DubboService.DataModle;
+using DubboNet.DubboService.Native;
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Text;
+using System.Text.Json;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace DubboNet.DubboService
+{
+    /// <summary>
+    /// 通过 Dubbo 3.3 引入的 HTTP/JSON 兼容端点调用 Dubbo Triple Java 接口一元方法。
+    /// EN: Invokes Dubbo Triple Java-interface unary methods through the 
HTTP/JSON
+    /// compatibility endpoint introduced by Dubbo 3.3.
+    /// </summary>
+    /// <remarks>
+    /// 第一期实现仅面向使用 <c>application/json</c> 的 Java 接口一元调用,不包含
+    /// Protobuf IDL、流式调用和带帧的 gRPC 线协议。
+    /// EN: This first implementation intentionally targets unary 
Java-interface calls
+    /// with <c>application/json</c>. Protobuf IDL, streaming and the framed 
gRPC
+    /// wire format are outside its scope.
+    /// </remarks>
+    public sealed class TripleDubboActuatorSuite :
+        IDubboActuatorSuite,
+        IDubboGenericInvocationActuator
+    {
+        private const string ServiceVersionHeader = "tri-service-version";
+        private const string ServiceGroupHeader = "tri-service-group";
+        private const string ServiceTimeoutHeader = "tri-service-timeout";
+
+        private static readonly HashSet<string> ReservedRequestHeaders =
+            new HashSet<string>(StringComparer.OrdinalIgnoreCase)
+            {
+                "host",
+                "content-length",
+                "content-type",
+                "grpc-timeout",
+                ServiceVersionHeader,
+                ServiceGroupHeader,
+                ServiceTimeoutHeader
+            };
+
+        private sealed class ServiceMetadata
+        {
+            public string Version { get; set; }
+            public string Group { get; set; }
+            public int? Timeout { get; set; }
+        }
+
+        private readonly HttpClient _httpClient;
+        private readonly bool _ownsHttpClient;
+        private readonly int _requestTimeoutMilliseconds;
+        private readonly ConcurrentDictionary<string, ServiceMetadata> 
_services =
+            new ConcurrentDictionary<string, 
ServiceMetadata>(StringComparer.Ordinal);
+        private bool _disposed;
+
+        /// <inheritdoc/>
+        public DubboActuatorProtocolType ProtocolType => 
DubboActuatorProtocolType.Triple;
+
+        /// <inheritdoc/>
+        public string ServiceFuncSpit => "/";
+
+        /// <inheritdoc/>
+        public DubboActuatorSuiteStatus ActuatorSuiteStatusInfo { get; private 
set; } =
+            new DubboActuatorSuiteStatus();
+
+        /// <inheritdoc/>
+        public DateTime LastActivateTime { get; private set; } = DateTime.Now;
+
+        /// <summary>
+        /// 获取默认的 Java 服务接口名。
+        /// EN: Gets the default Java service interface name.
+        /// </summary>
+        public string DefaultServiceName { get; private set; }
+
+        /// <summary>
+        /// 使用指定地址和端口创建 Triple HTTP/JSON 执行器。
+        /// EN: Creates a Triple HTTP/JSON actuator from an address and port.
+        /// </summary>
+        /// <param name="address">Provider 地址。EN: Provider address.</param>
+        /// <param name="port">Provider 端口。EN: Provider port.</param>
+        /// <param name="dubboActuatorSuiteConf">执行器配置。EN: Actuator 
configuration.</param>
+        public TripleDubboActuatorSuite(
+            string address,
+            int port,
+            DubboActuatorSuiteConf dubboActuatorSuiteConf = null)
+            : this(
+                CreateHttpClient(address, port, dubboActuatorSuiteConf),
+                dubboActuatorSuiteConf,
+                true)
+        {
+        }
+
+        /// <summary>
+        /// 使用网络端点创建 Triple HTTP/JSON 执行器。
+        /// EN: Creates a Triple HTTP/JSON actuator from a network endpoint.
+        /// </summary>
+        /// <param name="endPoint">Provider 网络端点。EN: Provider network 
endpoint.</param>
+        /// <param name="dubboActuatorSuiteConf">执行器配置。EN: Actuator 
configuration.</param>
+        public TripleDubboActuatorSuite(
+            IPEndPoint endPoint,
+            DubboActuatorSuiteConf dubboActuatorSuiteConf = null)
+            : this(
+                endPoint?.Address.ToString()
+                    ?? throw new ArgumentNullException(nameof(endPoint)),
+                endPoint.Port,
+                dubboActuatorSuiteConf)
+        {
+        }
+
+        internal TripleDubboActuatorSuite(
+            HttpClient httpClient,
+            DubboActuatorSuiteConf dubboActuatorSuiteConf = null)
+            : this(httpClient, dubboActuatorSuiteConf, false)
+        {
+        }
+
+        private TripleDubboActuatorSuite(
+            HttpClient httpClient,
+            DubboActuatorSuiteConf dubboActuatorSuiteConf,
+            bool ownsHttpClient)
+        {
+            _httpClient = httpClient ?? throw new 
ArgumentNullException(nameof(httpClient));
+            if (_httpClient.BaseAddress == null)
+            {
+                throw new ArgumentException(
+                    "Triple HttpClient must define BaseAddress.",
+                    nameof(httpClient));
+            }
+
+            DubboActuatorSuiteConf configuration =
+                dubboActuatorSuiteConf ?? new DubboActuatorSuiteConf();
+            DefaultServiceName = configuration.DefaultServiceName;
+            _requestTimeoutMilliseconds = Math.Max(1, 
configuration.DubboRequestTimeout);
+            _ownsHttpClient = ownsHttpClient;
+        }
+
+        internal void RegisterService(DubboServiceEndPointInfo endpoint)
+        {
+            if (endpoint == null)
+            {
+                throw new ArgumentNullException(nameof(endpoint));
+            }
+            if (string.IsNullOrWhiteSpace(endpoint.Interface))
+            {
+                return;
+            }
+
+            _services[endpoint.Interface] = new ServiceMetadata
+            {
+                Version = endpoint.Version,
+                Group = endpoint.Group,
+                Timeout = endpoint.Timeout
+            };
+        }
+
+        /// <inheritdoc/>
+        public Task<DubboRequestResult> SendQuery(string endPoint)
+        {
+            return SendQuery(endPoint, string.Empty);
+        }
+
+        /// <inheritdoc/>
+        public Task<DubboRequestResult> SendQuery(string endPoint, string req)
+        {
+            if (!string.IsNullOrWhiteSpace(DefaultServiceName)
+                && !string.IsNullOrWhiteSpace(endPoint)
+                && !endPoint.Contains("#")
+                && !endPoint.Contains("/")
+                && !endPoint.Contains("."))
+            {
+                endPoint = $"{DefaultServiceName}.{endPoint}";
+            }
+
+            DubboInvocation invocation = 
NativeDubboCodec.ParseInvocation(endPoint, req);
+            return SendQuery(invocation);
+        }
+
+        /// <inheritdoc/>
+        public Task<DubboRequestResult> SendQuery(DubboInvocation invocation)
+        {
+            return SendQuery(invocation, CancellationToken.None);
+        }
+
+        /// <inheritdoc/>
+        public async Task<DubboRequestResult> SendQuery(
+            DubboInvocation invocation,
+            CancellationToken cancellationToken)
+        {
+            if (_disposed)
+            {
+                throw new 
ObjectDisposedException(nameof(TripleDubboActuatorSuite));
+            }
+
+            invocation.Validate();
+            LastActivateTime = DateTime.Now;
+            Stopwatch stopwatch = Stopwatch.StartNew();
+            DubboRequestResult result = new DubboRequestResult
+            {
+                ServiceElapsed = 0,
+                ServiceElapsedAvailable = false
+            };
+
+            _services.TryGetValue(invocation.Service, out ServiceMetadata 
metadata);
+            string version = FirstNonBlank(invocation.Version, 
metadata?.Version);
+            string group = FirstNonBlank(invocation.Group, metadata?.Group);
+            int timeoutMilliseconds = Math.Max(
+                1,
+                metadata?.Timeout ?? _requestTimeoutMilliseconds);
+
+            string requestPath = 
$"/{Uri.EscapeDataString(invocation.Service)}" +
+                $"/{Uri.EscapeDataString(invocation.Method)}";
+            string requestBody = 
JsonSerializer.Serialize(invocation.Arguments);
+
+            try
+            {
+                // ResponseHeadersRead ends HttpClient.Timeout at the headers. 
Keep a

Review Comment:
   复核确认:这条在 **74bbca3** 上仍然成立,没有随 .NET 10 / 运行时端点那次改动消失。所以本轮不再重复开新线程,只在这里留个状态。
   
   两个计时器依然并存,而且新的 per-call linked CTS 是**后**建的那个,谁先到谁说了算:
   
   - `TripleDubboActuatorSuite.cs:400`:`HttpClient.Timeout = Max(1, 
DubboRequestTimeout)`(客户端默认值)
   - `TripleDubboActuatorSuite.cs:241` 
起:`CancelAfter(timeoutMilliseconds)`(provider URL 里广告的 `metadata.Timeout`)
   
   当 provider 声明的 `timeout` **大于**客户端默认值时,请求会先被 `HttpClient.Timeout` 
掐断,`metadata.Timeout` 永远没机会生效——这正好是「服务端要求更宽容、客户端先超时」这种最常见的调优场景。反过来 `timeout` 
更小时,两个计时器都在跑,只是 linked CTS 
先触发,行为看起来正常,所以现有测试(`HttpClient{Timeout=InfiniteTimeSpan}`)测不出来。
   
   最小改法还是上次那条:`Timeout = Timeout.InfiniteTimeSpan`,把这个 per-call 的 linked CTS 
作为唯一定时源。如果担心「客户端默认值必须有效」,那就把 `DubboRequestTimeout` 和 `metadata.Timeout` 的取舍写成 
`Min(...)` 并加注释说明谁优先,而不是让两个机制隐式竞争。



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