fix(connector-fabric): always disconnect gateway in API methods
Summary
- Add
try/finallywithgateway.disconnect()to 5 Fabric connector API methods that were leaking gateway connections
Problem
Four methods created a Fabric Gateway via createGatewayWithOptions() but never called gateway.disconnect():
getBlock()getChainInfo()getTransactionReceiptByTxID()getDiscoveryResults()
Each call leaked open gRPC connections to every discovered Fabric peer and orderer. Additionally, transact() only disconnected on the success path — any error (endorsement failure, timeout, chaincode error) leaked the gateway.
Under production load this caused gRPC connection exhaustion on Fabric peers, file descriptor exhaustion (EMFILE), and memory leaks.
Changes
File: packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts
| Method | Change |
|---|---|
transact() |
Moved gateway.disconnect() from success-only path to finally block |
getTransactionReceiptByTxID() |
Added try/finally with gateway.disconnect() |
getBlock() |
Added try/finally with gateway.disconnect() |
getChainInfo() |
Added try/finally with gateway.disconnect() |
getDiscoveryResults() |
Added try/finally with gateway.disconnect() |
Test plan
- [ ] Run existing Fabric connector integration tests
- [ ] Verify all 5 methods return correct results
- [ ] Verify transact() cleans up on both success and failure
- [ ] Under load, confirm no gRPC connection accumulation (check with
lsof)
Fixes #4186
@LordKubaya thanks for approving! I shortened the commit title (now within the 72-char limit) and updated the PR title. No code changes were made.
@mn-ram thank you for the PR. Please check the yarn-lint job, which is failing
Addressed the Copilot feedback:
-Moved gateway creation inside the try block in transact() so errors are properly caught.
-Moved the "Creating Fabric Gateway instance" log before the createGateway() call for correct order.
-Fixed two "it's" → "its" typos in getBlock debug messages.
Also fixed the lint issue. yarn lint now passes locally.
Hi @RafaelAPB ,
Just a gentle follow-up on this PR. I’ve addressed the previous feedback and fixes, including the lint issues. There are still a couple of checks pending/failing, and I’m happy to take care of those if needed.
Would really appreciate your review when you get a chance. Thanks!