From 6a81761f32ed310038aad07668b8228067e455c6 Mon Sep 17 00:00:00 2001 From: Xuewei Niu Date: Tue, 15 Aug 2023 16:48:14 +0800 Subject: [PATCH] fix(config): An issue that random ports can't be assgined The condition of assigning a random port for protocols should be that port is less than or equal to 0, not the length of the port string. Fixes: #2382 Signed-off-by: Xuewei Niu --- config/service_config.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/service_config.go b/config/service_config.go index fb9723367b..976071a2bf 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -209,7 +209,12 @@ func (s *ServiceConfig) IsExport() bool { func getRandomPort(protocolConfigs []*ProtocolConfig) *list.List { ports := list.New() for _, proto := range protocolConfigs { - if len(proto.Port) > 0 { + if port, err := strconv.Atoi(proto.Port); err != nil { + logger.Infof( + "%s will be assgined to a random port, since the port is an invalid number", + proto.Name, + ) + } else if port > 0 { continue }