From cc1f480aa994efc52a9eb090700e13f659e73a6d Mon Sep 17 00:00:00 2001
From: Joe Zou <yixian.zou@gmail.com>
Date: Tue, 14 Apr 2020 22:06:41 +0800
Subject: [PATCH] modify start provider with random port

---
 config/service_config.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/config/service_config.go b/config/service_config.go
index c99660461..f1ea65889 100644
--- a/config/service_config.go
+++ b/config/service_config.go
@@ -106,6 +106,11 @@ func NewServiceConfig(id string, context context.Context) *ServiceConfig {
 	}
 }
 
+// Get Random Ports with no size
+func getRandomPort() int {
+	return getRandomPorts(1)[0]
+}
+
 // Get Random Ports with size
 func getRandomPorts(size int) []int {
 	ports := make([]int, 0, size)
@@ -164,8 +169,7 @@ func (c *ServiceConfig) Export() error {
 		return nil
 	}
 
-	ports := getRandomPorts(protocolSize)
-	for i, proto := range protocolConfigs {
+	for _, proto := range protocolConfigs {
 		// registry the service reflect
 		methods, err := common.ServiceMap.Register(c.InterfaceName, proto.Name, c.rpcService)
 		if err != nil {
@@ -175,7 +179,7 @@ func (c *ServiceConfig) Export() error {
 		}
 		port := proto.Port
 		if len(proto.Port) == 0 {
-			port = strconv.Itoa(ports[i])
+			port = strconv.Itoa(getRandomPort())
 		}
 		ivkURL := common.NewURLWithOptions(
 			common.WithPath(c.id),
-- 
GitLab