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
- Execute a command that triggers
SubmitTransaction or SubmitTransactionWithWait.
- Execute a second command/operation within the same session that attempts to reuse the cached
ordererClient or notificationClient.
- 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.
Description
In
app/submit.go, bothSubmitTransactionandSubmitTransactionWithWaitcalldefer func() { _ = sc.ordererClient.Close() }().The
ordererClientis obtained fromOrdererProvider.Get()which usessync.Once(provider.go) to cache the instance. Because of this, after the first submission closes the client, subsequent calls toOrdererProvider.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
SubmitTransactionorSubmitTransactionWithWait.ordererClientornotificationClient.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.Onceprovider to properly cache the open connections and only let them close when the application process terminates.