Alanxtl commented on code in PR #3812:
URL: https://github.com/apache/dubbo-go/pull/3812#discussion_r4581401484


##########
protocol/triple/triple_protocol/client.go:
##########
@@ -210,10 +221,17 @@ func (c *Client) newConn(ctx context.Context, streamType 
StreamType, method stri
        if interceptor := c.config.Interceptor; interceptor != nil {
                newConn = interceptor.WrapStreamingClient(newConn)
        }
+       if resources := c.config.CodecResources; resources != nil {

Review Comment:
   newConn 在创建流时获取资源租约,但 CallServerStream 的 CloseRequest 
失败分支直接返回,没有关闭响应或释放租约。对实现了 io.Closer 的插件,后续销毁 invoker 时的 Resources.Close() 
会一直等待。注入写入关闭错误后,我复现了这一阻塞;失败路径需要释放连接和租约。



##########
client/action.go:
##########
@@ -181,19 +190,44 @@ func (refOpts *ReferenceOptions) refer(srv 
common.RPCService, info *ClientInfo)
        }
        refOpts.postProcessConfig(cfgURL)
 
+       extension.SnapshotSerializationPolicy(cfgURL)
+
        // if mesh-enabled is set
        updateOrCreateMeshURL(refOpts)
 
        // retrieving urls from config, and appending the urls to refOpts.urls
        urls, err := processURL(ref, refOpts.Registries, cfgURL)
        if err != nil {
-               panic(err)
+               return err
        }
 
+       preparedURLs := make([]*common.URL, 0, len(urls))
+       prepared := false
+       defer func() {
+               if !prepared {
+                       for i := len(preparedURLs) - 1; i >= 0; i-- {
+                               _ = extension.ReleaseCodecURL(preparedURLs[i], 
"consumer")
+                       }
+               }
+       }()
+       for _, url := range urls {
+               target := url
+               // Both registry URL forms wrap the business protocol that owns 
codecs.
+               if url.Protocol == constant.RegistryProtocol || url.Protocol == 
constant.ServiceRegistryProtocol {
+                       target = url.SubURL
+               }
+               if target != nil {
+                       if prepareErr := extension.PrepareCodecURL(target, 
"consumer"); prepareErr != nil {

Review Comment:
   这里成功创建了插件绑定,但默认 Dial 和旧版 stub 可能走 NewDubbo3Invoker,该路径仍从旧的 Triple codec 
注册表取序列化器,不使用新绑定。我用 MessageMode 插件复现:`Dial` 成功,首次 RPC 返回 serialization ... not 
impl in triple client api。需要让旧客户端接入新绑定,或在初始化时明确拒绝不支持的组合。



##########
protocol/triple/triple_protocol/codec.go:
##########
@@ -641,16 +666,37 @@ func (s *tripleServerCodecSession) Name() string { return 
s.delegate.Name() }
 // hessian2 is always allowed (Non-IDL interop default); any other name must
 // match the provider's configured serialization.
 func (s *tripleServerCodecSession) checkAllowed(codecName string) error {
+       if s.runtimeCodecs != nil {
+               _, err := resolveRuntimeInner(s.runtimeCodecs, codecName)
+               return err
+       }
        if codecName == codecNameHessian2 || codecName == 
s.allowedSerializeType {
                return nil
        }
        return fmt.Errorf("serialize type %q not allowed by provider (allowed: 
%s, %s)",
                codecName, codecNameHessian2, s.allowedSerializeType)
 }
 
+func (s *tripleServerCodecSession) unmarshalEmpty(message any) error {
+       return s.Unmarshal(nil, message)
+}
+
 func (s *tripleServerCodecSession) Unmarshal(data []byte, message any) error {
+       if s.runtimeCodecs != nil && s.delegate.Name() != "proto" {

Review Comment:
   默认接收列表中的键是 json,但 Content-Type: application/json; charset=utf-8 选中的 codec 
名称是 json; charset=utf-8,因此检查失败。相同请求在未启用新配置的 handler 上返回 200,在新 handler 上返回 
400。应在检查策略前将别名归一化。



##########
protocol/triple/triple_protocol/envelope.go:
##########
@@ -187,6 +187,13 @@ func (r *envelopeReader) Unmarshal(message any) *Error {
                env.Data.Len() == 0:
                // This is a standard message (because none of the top 7 bits 
are set) and
                // there's no data, so the zero value of the message is correct.
+               // Configured sessions must still validate message permission 
and wrapper
+               // structure; legacy codecs retain their historical 
empty-message shortcut.
+               if codec, ok := r.codec.(interface{ unmarshalEmpty(any) error 
}); ok {

Review Comment:
   新增的空消息检查只对实现了 unmarshalEmpty 的 codec 生效;客户端配置的普通插件和 protoWrapperCodec 
都没有实现。实测对端发送零长度 gRPC envelope 且状态为成功时,消息插件的 Unmarshal 未被调用;wrapped-object 
客户端即使配置空接收列表也返回成功。客户端需要对空响应执行相应的解码和策略检查。



##########
protocol/triple/server.go:
##########
@@ -245,6 +247,13 @@ func (s *Server) startTransport(callProtocol string, 
tlsConf *tls.Config) {
 
 func (s *Server) registerServiceHandlers(invoker base.Invoker, info 
*common.ServiceInfo, handlerOpts []tri.HandlerOption) {
        url := invoker.GetURL()
+       if raw, ok := 
url.GetAttribute("triple.serialization.resources.provider"); ok {

Review Comment:
   服务的资源被加入服务器级列表,但只在整个 Triple server 停止时关闭。实测 ServiceOptions.Unexport() 后插件的 
Close 调用次数仍为 0。长期运行的进程动态上下线服务时,这些资源会持续保留;应在对应服务退役且在途调用结束后释放。



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