Aetherance opened a new pull request, #3216:
URL: https://github.com/apache/dubbo-go/pull/3216

   ### Description
   在一些情况下,client 配置了 affinity router 时,会直接因为 nil 而段错误
   ```
   2026-02-17 21:27:55     ERROR   affinity/router.go:90       Application 
affinity router must set application name
   2026/02/17 21:27:55 Authenticated: id=72061538416853150, timeout=4000
   panic: runtime error: invalid memory address or nil pointer dereference
   [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xe915e9]
   ```
   
   该 bug 一般发生在 配置了 application affinity router 时
   
   配置代码:
   client:
   ```go
        conn, _, _ := zk.Connect([]string{"127.0.0.1:2181"}, time.Second*5)
        defer conn.Close()
        
conn.Create("/dubbo/config/dubbo/router_affinity_consumer.affinity-router", 
[]byte(`configVersion: v3.1
   scope: application
   key: router_affinity_consumer
   enabled: true
   runtime: true
   affinityAware:
     key: region
     ratio: 1`), 0, zk.WorldACL(zk.PermAll))
   
        ins, _ := dubbo.NewInstance(
                dubbo.WithName("router_affinity_consumer"),
                dubbo.WithRegistry(registry.WithZookeeper(), 
registry.WithAddress("127.0.0.1:2181")),
                dubbo.WithConfigCenter(config_center.WithZookeeper(), 
config_center.WithAddress("127.0.0.1:2181"), config_center.WithGroup("dubbo")),
        )
   
        cli, _ := ins.NewClient(client.WithClientProtocolTriple())
        svc, _ := greet.NewGreetService(cli, client.WithParam("region", 
"shanghai"))
   
        ctx := context.WithValue(context.Background(),
                constant.DubboCtxKey("attachment"),
                map[string]interface{}{"region": "shanghai"},
        )
   ```
   
   server:
   ```go
        ins, _ := dubbo.NewInstance(
                dubbo.WithName("router_affinity_provider_a"),
                dubbo.WithRegistry(registry.WithZookeeper(), 
registry.WithAddress("127.0.0.1:2181")),
        )
   
        srv, _ := 
ins.NewServer(server.WithServerProtocol(protocol.WithTriple(), 
protocol.WithPort(20000)))
   
        handler := &AffinityGreetServer{}
        greet.RegisterGreetServiceHandler(srv, handler, 
server.WithParam("region", "hangzhou"))
   
        srv.Serve()
   ```
   
   该 bug 只会在配置了 application 模式的 affinity router 上出现,如果配置 service 模式的 affinity 
router 则不会触发该 bug
   
   bug 原因是当前版本的client应用名未能被正确传递至 router chain。这导致 router chain 在 初始化 affinity 
router 时,由于获取到空应用名而直接返回 nil。最终造成 nil 被访问而 panic
   
   本 pr 添加了在 router chain 读取应用名的逻辑来修复此 bug
   
   Fixes #3203
   
   ### Checklist
   - [x] I confirm the target branch is `develop`
   - [x] Code has passed local testing
   - [x] I have added tests that prove my fix is effective or that my feature 
works
   


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