Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpcx: grpcx.Server.ServerConfig.Name contains "/" and will report an error #4180

Open
ynwcel opened this issue Mar 3, 2025 · 0 comments
Open
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@ynwcel
Copy link
Contributor

ynwcel commented Mar 3, 2025

Go version

go 1.24.0

GoFrame version

2.8.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

1. hello.proto

syntax="proto3";

option go_package="gfgrpcx/demo2/api";

message HelloReq {
    string name=1;
}

message HelloRes{
    string reply=1;
}

service hello{
    rpc Hello(HelloReq) returns(HelloRes);
}

2. main.go

package main

import (
	"context"
	"fmt"
	"gfgrpxc/demo2/api"
	"os"
	"sync"
	"time"

	"github.com/gogf/gf/contrib/registry/file/v2"
	"github.com/gogf/gf/contrib/rpc/grpcx/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
)

type Controller struct {
	api.UnimplementedHelloServer
}

func Register(s *grpcx.GrpcServer) {
	api.RegisterHelloServer(s.Server, &Controller{})
}

func (*Controller) Hello(ctx context.Context, req *api.HelloReq) (res *api.HelloRes, err error) {
	res = &api.HelloRes{
		Reply: fmt.Sprintf("gogf-server-reply:hello %s", req.Name),
	}
	return
}

func main() {
	if len(os.Args) <= 1 {
		fmt.Printf("Usage: %s <servername>\n", os.Args[0])
		return
	}
	grpcx.Resolver.Register(etcd.New("192.168.100.100:2379"))
	var (
		wg         = new(sync.WaitGroup)
		servername = os.Args[1]
	)
	wg.Add(2)
	go func() {
		defer wg.Done()
		server(servername)
	}()
	go func() {
		defer wg.Done()
		time.Sleep(time.Second * 2)
		client(servername)
	}()
	wg.Wait()
}

func server(servername string) {
	scfg := &grpcx.GrpcServerConfig{
		Name: servername,
	}
	server := grpcx.Server.New(scfg)
	Register(server)
	server.Run()

}
func client(servername string) {
	var (
		ctx    = grpcx.Ctx.NewOutgoing(gctx.GetInitCtx(), nil)
		conn   = grpcx.Client.MustNewGrpcClientConn(servername)
		client = api.NewHelloClient(conn)
		req    = &api.HelloReq{
			Name: servername,
		}
		res *api.HelloRes
		err error
	)
	if res, err = client.Hello(ctx, req); err != nil {
		g.Log().Error(ctx, err)
	}
	g.Log().Infof(ctx, "%#v", res)
}

What did you see happen?

运行情况

1、servername = "demo2"

go run main.go demo2
2025-03-03 16:30:37.731 [DEBU] service register: &{Head: Deployment: Namespace: Name:demo2 Version: Endpoints:192.168.100.1:56586,192.168.2.15:56586 Metadata:map[protocol:grpc]}
2025-03-03 16:30:37.736 [DEBU] etcd put success with key "/service/default/default/demo2/latest/192.168.100.1:56586,192.168.2.15:56586", value "{"protocol":"grpc"}", lease "7587884632992045171"
2025-03-03 16:30:37.736 [INFO] pid[48656]: grpc server started listening on [:56586]
2025-03-03 16:30:39.709 [DEBU] Watch key "/service/default/default/demo2/latest/"
2025-03-03 16:30:39.711 [DEBU] client conn updated with addresses [{"Addr":"192.168.100.1:56586","ServerName":"demo2","Attributes":{"protocol":"grpc","RawService":"\u003c0xc0002e2930\u003e"},"BalancerAttributes":null,"Metadata":null},{"Addr":"192.168.2.15:56586","ServerName":"demo2","Attributes":{"protocol":"grpc","RawService":"\u003c0xc0002e2930\u003e"},"BalancerAttributes":null,"Metadata":null}]
2025-03-03 16:30:39.712 [DEBU] client conn updated with addresses [{"Addr":"192.168.100.1:56586","ServerName":"demo2","Attributes":{"protocol":"grpc","RawService":"\u003c0xc000688570\u003e"},"BalancerAttributes":null,"Metadata":null},{"Addr":"192.168.2.15:56586","ServerName":"demo2","Attributes":{"protocol":"grpc","RawService":"\u003c0xc000688570\u003e"},"BalancerAttributes":null,"Metadata":null}]
2025-03-03 16:30:39.712 [INFO] &api.HelloRes{state:impl.MessageState{NoUnkeyedLiterals:pragma.NoUnkeyedLiterals{}, DoNotCompare:pragma.DoNotCompare{}, DoNotCopy:pragma.DoNotCopy{}, atomicMessageInfo:(*impl.MessageInfo)(0xc000388170)}, sizeCache:0, unknownFields:[]uint8(nil), Reply:"gogf-server-reply:hello demo2"}
2025-03-03 16:30:59.186 [INFO] signal received: interrupt, gracefully shutting down
2025-03-03 16:30:59.186 [DEBU] service deregister: &{Service:0xc00010c380 Endpoints:192.168.100.1:56586,192.168.2.15:56586 Metadata:map[protocol:grpc]}

2、servername = "gogf-grpcx/demo2"

go run main.go gogf-grpcx/demo2
2025-03-03 16:15:12.353 [DEBU] service register: &{Head: Deployment: Namespace: Name:gogf-grpcx/demo2 Version: Endpoints:192.168.100.1:55358,192.168.2.15:55358 Metadata:map[protocol:grpc]}
2025-03-03 16:15:12.354 [INFO] pid[29984]: grpc server started listening on [:55358]
2025-03-03 16:15:15.060 [DEBU] Watch key "/service/default/default/gogf-grpcx/demo2/latest/"
panic: invalid address "latest" for creating endpoint, endpoint address is like "ip:port"
2025-03-03 16:15:15.060 [DEBU] Watch key "/service/default/default/gogf-grpcx/demo2/latest/"
panic: invalid address "latest" for creating endpoint, endpoint address is like "ip:port"
panic: invalid address "latest" for creating endpoint, endpoint address is like "ip:port"

goroutine 19 [running]:
github.com/gogf/gf/v2/net/gsvc.NewEndpoint({0xc0000f462a, 0x6})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/v2@v2.8.3/net/gsvc/gsvc_endpoint.go:30 +0x125
github.com/gogf/gf/v2/net/gsvc.NewEndpoints({0xc0000f462a?, 0x56?})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/v2@v2.8.3/net/gsvc/gsvc_endpoints.go:19 +0x95
github.com/gogf/gf/v2/net/gsvc.NewServiceWithKV({0xc0000f4600, 0x57}, {0xc000037200, 0x34})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/v2@v2.8.3/net/gsvc/gsvc_service.go:57 +0xa5
github.com/gogf/gf/contrib/registry/file/v2.(*Registry).getServiceByFilePath(0x119392f?, {0xc00025ecb0, 0x6d})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/contrib/registry/file/v2@v2.8.3/file_discovery.go:120 +0xdd
github.com/gogf/gf/contrib/registry/file/v2.(*Registry).getServices(0xc000049190, {0x129a7c8, 0xc00013ad20})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/contrib/registry/file/v2@v2.8.3/file_discovery.go:86 +0x118
github.com/gogf/gf/contrib/registry/file/v2.(*Registry).Search(0xc000049190, {0x129a7c8?, 0xc00013ad20?}, {{0xc0000371ca, 0x31}, {0x0, 0x0}, {0x0, 0x0}, 0x0})
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/contrib/registry/file/v2@v2.8.3/file_discovery.go:24 +0x37
github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/resolver.(*Resolver).watch(0xc0002523c0)
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/contrib/rpc/grpcx/v2@v2.8.3/internal/resolver/resolver_resolver.go:41 +0x62
created by github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/resolver.(*Builder).Build in goroutine 14
        C:/Users/LY/go/pkg/mod/github.com/gogf/gf/contrib/rpc/grpcx/v2@v2.8.3/internal/resolver/resolver_builder.go:56 +0x268
exit status 2

What did you expect to see?

Image

@ynwcel ynwcel added the bug It is confirmed a bug, but don't worry, we'll handle it. label Mar 3, 2025
@Issues-translate-bot Issues-translate-bot changed the title os/gtime: issue grpcx.Server.ServerConfig.Name 包含 "/" 会报错 os/gtime: issue grpcx.Server.ServerConfig.Name contains "/" and will report an error Mar 3, 2025
@ynwcel ynwcel changed the title os/gtime: issue grpcx.Server.ServerConfig.Name contains "/" and will report an error grpcx: grpcx.Server.ServerConfig.Name contains "/" and will report an error Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant