cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.31k stars 520 forks source link

对Hertz做服务发现的注册时,启动Listen任意端口时,Transport最终使用的端口无法正确传给Registry #1062

Open hgcncn opened 9 months ago

hgcncn commented 9 months ago

https://github.com/cloudwego/hertz/blob/532011f36abee9d74dfc75efeef065d5c6fa64df/pkg/app/server/hertz.go#L132 这里仅使用opt中的registry info,而kitex在启动后会更新registry info

对应现象是hertz能正常监听到任意端口,但在initOnRunHooks时,没有用监听到的端口地址去配置服务发现

2024/02/04 19:38:38.789411 main.go:31: [Info]  addr: :0
2024/02/04 19:38:38.789896 engine.go:389: [Info] HERTZ: Using network library=netpoll
2024/02/04 19:38:38.790097 transport.go:109: [Info] HERTZ: HTTP server listening on address=[::]:65094
2024/02/04 19:38:39.792078 hertz.go:133: [Error] HERTZ: Register error=parsing addr failed, err: invalid port 0
2024/02/04 19:38:39.795917 hertz.go:70: [Error] HERTZ: Receive close signal: error=parsing addr failed, err: invalid port 0

注册相关代码

    address, _ := net.ResolveTCPAddr("tcp", ":")
    blog.Infof("addr: %s", address.String())
    h := server.Default(
        server.WithHostPorts(address.String()),
        server.WithRegistry(r, &registry.Info{
            ServiceName: "demo.api.client",
            Addr:        address,
        }),
    )
github-actions[bot] commented 9 months ago

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

li-jin-gou commented 9 months ago

我们优化一下 cc @Skyenought

li-jin-gou commented 9 months ago

快速解决方案是手动先指定一下 IP/Port 获取一下 loccal 的

hgcncn commented 9 months ago

快速解决方案是手动先指定一下 IP/Port 获取一下 loccal 的

已经按这个方式本地绕过~

li-jin-gou commented 9 months ago

快速解决方案是手动先指定一下 IP/Port 获取一下 loccal 的

已经按这个方式本地绕过~

OK

li-jin-gou commented 9 months ago

cc @ViolaPioggia