hyperledger/fabric-sdk-go

gateway should implement function close()

1170300722 opened this issue · 1 comments

now it is :

// Close the gateway connection and all associated resources, including removing listeners attached to networks and
// contracts created by the gateway.
func (gw *Gateway) Close() {
	// future use
}

after connect gateway ,get network and submit Transaction, I cannot break the tcp connection.

gw, err := gateway.Connect(
		gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
		gateway.WithUser(userid),
	)
...
network, err := gw.GetNetwork(channel)
...
connector.UseContract(..., ...)
funcName = "QueryAllRecords"
result, err = connector.Contract.EvaluateTransaction(funcName)

I can read the leadger by doing this ,the var result is expected, but I notice the connection is still active, I cannot close the gateway connection, after invoking chaincode some times ,the connection is getting more

root@hecs-ubuntu-18:/home/localrootchain/service_proxy# netstat -ap | grep serviceProxy
tcp        0      0 192.168.0.16:60070      peer0.cn:8050           ESTABLISHED 1249/./serviceProxy 
tcp        0      0 192.168.0.16:34686      peer0.cn:8050           ESTABLISHED 1249/./serviceProxy 
tcp        0      0 192.168.0.16:41730      peer0.cn:7050           ESTABLISHED 1249/./serviceProxy 
tcp        0      0 192.168.0.16:41282      peer0.cn:7050           ESTABLISHED 1249/./serviceProxy 
tcp        0      0 192.168.0.16:41050      peer0.cn:7050           ESTABLISHED 1249/./serviceProxy 
tcp        0      0 192.168.0.16:59808      peer0.cn:8050           ESTABLISHED 1249/./serviceProxy 
tcp6       0      0 [::]:8001               [::]:*                  LISTEN      1249/./serviceProxy

more and more memory and cpu is occupied ,and I cannot close the sdk in gateway because it is not leaked, it is in lower case

type Gateway struct {
	sdk        *fabsdk.FabricSDK
	options    *gatewayOptions
	cfg        core.ConfigBackend
	org        string
	mspid      string
	peers      []fab.PeerConfig
	mspfactory api.MSPProviderFactory
}

after some time, the gateway will write log as "error from discovery request...."so many times ,I think it is reported byhttps://github.com/hyperledger/fabric-sdk-go/blob/main/pkg/client/common/discovery/dynamicdiscovery/chservice.go#L120
besides ,I can find many tcp connection and I can hardly query ledger ,peer will response like "context deadline exceeded".
nothing i can do, i just restart my client, and it will work fine for some time ,and the same problem will appear again.
How can I Close the gateway connection and all associated resources?

I was intended to write like

gw, err := gateway.Connect(
		gateway.WithConfig(config.FromFile(filepath.Clean(ccpPath))),
		gateway.WithUser(userid),
	)
defer gw.Close()

but as we know ,it wont be closed, it hasnt been implement ,and nothing will happen