-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak when gateway.connect and gateway.disconnect are called repeatedly #529
Comments
I can observe similar characteristics over a 5 minute run of your test application, with an initial state of
And at the end of the 5 minute run of:
Then after a few seconds pause to give the garbage collector a chance to do some cleanup a final state of:
It would need some profiling of the heap to identify exactly what was using the space and confirm it isn't caused by some other aspect of Node runtime or heap management. I must point out that creating and discarding large numbers of connections is not good practice. You generally want to keep your Gateway connection around and use it for all work carried out by a client identity. |
One other thing is that the sample client code you posted does not wait for completion of the async |
I have seen the same behaviour and noticed that the grpc connections remain open both on the client as well as the peer. Running the same version of the sdk, fabric-peer 2.2.2. |
We notice the same issue here. In our project we create gateway-> connect -> disconnect. The memory keeps leakage and if we stop client process, client and peer memory suddenly released. |
Aside from memory problems, this also causes connections to remain open. This can eventually cause a server to run out of available connections, as also reported here: https://stackoverflow.com/questions/49695485/network-leak-issue-with-event-hub-and-peer-connections-in-fabric-client-node-js I understand the intention is not to use gateways rapidly, but that should be a performance consideration, and not a reason to leave memory and connections hanging. Has anyone found a solution to this, other than forcibly restarting the node process the gateway is connecting through? |
Any news on this? |
I managed to reduce connection leak by doing two things (both):
It worked in my case (for connection leaks, I didn't check memory leaks), but it was a lot of debugging and experiments. It reduced all connection leaks for successful chaincode invocations, but left some when chaincode invocation failed. Maybe it will help someone with debugging this stuff. I will probably give up and use Fabric Gateway for Fabric 2.4 anyway (https://github.com/hyperledger/fabric-gateway). await gateway.connect(connProfile);
peerNames.forEach(peerName => {
// @ts-ignore
gateway.client.endorsers.get(peerName).disconnect(); // those connections will be replaced by new ones, but there will be no leak
});
const network = await gateway.getNetwork(channelName);
const fabricDiscoveryService = network.discoveryService; // get the reference here, not after calling contract
...
fabricDiscoveryService.close();
gateway.disconnect(); |
I've experiencing the same issue on Debian11, with fabric node SDK 2.2.15, and fabric 2.4.x. I will attempt the workaround proposed by @dzikowski . |
A slight change to connection closing was deliver in the v2.2.17 release, which might help with this issue. The workaround mentioned above does not seem ideal but the handling of connections created during connection profile handling does sound like a good candidate for the problem area - thank you @dzikowski for the investigation. If you are using (or can use) Fabric v2.4 or later, you should use the Fabric Gateway client API, which has much more efficient connection behaviour. It can use a single gRPC connection (over which you have direct control) for all interactions with Fabric, regardless of the number of client identities you are working with. See the migration guide for details. |
I use sdk 2.2.18. Connect the fabric network and submit tens of transactions and then disconnect the network. It also ends with core dumped.
|
Is this a new problem that worked with previos SDK versions and has just started appearing with v2.2.18? It looks like a physical memory allocation failure in the Node runtime so it might be worth checking the version of Node you are using and also monitor the system memory used and available to the Node process. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@ConstantRohmer This repository contains the (legacy) SDK for Node.js client applications, and this issue relates to Node.js client application memory usage. For issues relating to the Fabric orderer, you need to use the core Fabric repository. |
Sorry for that, I didn't pay attention to the repo this issue was in. I will switch to the correct repo and ask my question again ! |
We found memory-leak behavior when we call gateway.connect and gateway.disconnect repeatedly,
though we expected that gateway.disconnect cleans up.
We tried executing the code attached to this issue on the following environments.
Then, we got logs as follows:
According to these logs,
the memory usage increases every time we call connect and disconnect functions.
We attached the code to this issue for reproduction.
sdk-sample.tar.gz
The text was updated successfully, but these errors were encountered: