From 076205a2908cc666c9a5f6d2495cdbeca98a3d6d Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Wed, 4 Sep 2024 18:59:18 +0800 Subject: [PATCH] feat: listen config --- pkg/common/startrpc/start.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/common/startrpc/start.go b/pkg/common/startrpc/start.go index 4091a5f6e..9c7280da1 100644 --- a/pkg/common/startrpc/start.go +++ b/pkg/common/startrpc/start.go @@ -54,7 +54,16 @@ func Start[T any](ctx context.Context, discovery *config.Discovery, prometheusCo log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcPort", rpcPort, "prometheusPorts", prometheusConfig.Ports) rpcTcpAddr := net.JoinHostPort(network.GetListenIP(listenIP), strconv.Itoa(rpcPort)) - listener, err := net.Listen( + + lc := net.ListenConfig{ + Control: func(network, address string, conn syscall.RawConn) error { + return conn.Control(func(fd uintptr) { + _ = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + }) + }, + } + listener, err := lc.Listen( + ctx, "tcp", rpcTcpAddr, )