hyperledger / hyperledger/fabric-x
bug(fxconfig): SubmitTransaction and SubmitTransactionWithWait close the orderer client after every call via sync.Once-cached provider
- Dominant language
- Go
- Stars
- 64
- Forks
- 80
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 15
Description
## Description
In `app/submit.go`, both `SubmitTransaction` and `SubmitTransactionWithWait` call `defer func() { _ = sc.ordererClient.Close() }()`.
The `ordererClient` is obtained from `OrdererProvider.Get()` which uses `sync.Once` (`provider.go`) to cache the instance. Because of this, after the first submission closes the client, subsequent calls to `OrdererProvider.Get()` return the same cached (but now closed) client.
This means the second and all subsequent transaction submissions will fail because they attempt to use a closed gRPC connection. The exact same issue applies to the notification client and the query client in `list.go`.
This behavior directly contradicts the intention of caching the provider instance, and is similar to previous issues (like #21) regarding the reuse of closed clients.
### Expected Behavior
The cached provider should manage the connection lifecycle. The clients should remain open for the duration of the CLI process so they can be reused for subsequent operations.
### Steps to Reproduce
1. Execute a command that triggers `SubmitTransaction` or `SubmitTransactionWithWait`.
2. Execute a second command/operation within the same session that attempts to reuse the cached `ordererClient` or `notificationClient`.
3. The second call fails with a closed gRPC connection error.
### Proposed Solution
Remove the `defer Close()` calls from:
- `SubmitTransaction` (`app/submit.go`)
- `SubmitTransactionWithWait` (`app/submit.go`)
- `ListNamespaces` (`app/list.go`)
This will allow the `sync.Once` provider to properly cache the open connections and only let them close when the application process terminates.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.