From 5cc2c62c66fef8abb294f8539499bd35fab9391e Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Thu, 7 Dec 2023 02:36:42 +0800 Subject: [PATCH] fix: GetFreePort() will get the same port (#18604) --- cmd/common-main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/common-main.go b/cmd/common-main.go index b5583ce96..fac015530 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -388,6 +388,11 @@ func handleCommonCmdArgs(ctx *cli.Context) { if err != nil { logger.FatalIf(err, "Unable to get free port for Console UI on the host") } + // hold the port + l, err := net.Listen("TCP", fmt.Sprintf(":%s", p.String())) + if err == nil { + defer l.Close() + } consoleAddr = net.JoinHostPort("", p.String()) }