You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/05/24 15:27:00 UTC

[GitHub] [dubbo-go] zouyx commented on a change in pull request #539: Fix: defer in loop will cause resource leak

zouyx commented on a change in pull request #539:
URL: https://github.com/apache/dubbo-go/pull/539#discussion_r429647811



##########
File path: config/service_config.go
##########
@@ -119,8 +119,8 @@ func getRandomPort(protocolConfigs []*ProtocolConfig) *list.List {
 		if err != nil {
 			panic(perrors.New(fmt.Sprintf("Get tcp port error,err is {%v}", err)))
 		}
-		defer tcp.Close()
 		ports.PushBack(strings.Split(tcp.Addr().String(), ":")[1])
+		tcp.Close()

Review comment:
       I thought may panic in line 122 ,so use defer in loop .
   In this case ,  resoure usage will under control . 
   what do you think?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org