From bff8b5d2f8aa109086c5610263f40fc0a1914cdc Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Mon, 30 Oct 2023 11:11:13 -0700 Subject: [PATCH] Add error handle for Stream() The patchset checks the potential returned error from the stream between peer and external chaincode. Change-Id: I8928e64ce09d6f6a0f2f411473d645c46a1b0db5 Signed-off-by: Baohua Yang Signed-off-by: Baohua Yang --- core/chaincode/extcc/extcc_handler.go | 4 +++- core/chaincode/extcc/extcc_handler_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/chaincode/extcc/extcc_handler.go b/core/chaincode/extcc/extcc_handler.go index 79a30333cd1..70245e36855 100644 --- a/core/chaincode/extcc/extcc_handler.go +++ b/core/chaincode/extcc/extcc_handler.go @@ -58,7 +58,9 @@ func (i *ExternalChaincodeRuntime) Stream(ccid string, ccinfo *ccintf.ChaincodeS } // peer as client has to initiate the stream. Rest of the process is unchanged - sHandler.HandleChaincodeStream(stream) + if err := sHandler.HandleChaincodeStream(stream); err != nil { + return errors.WithMessagef(err, "error handling chaincode stream for %s", ccid) + } extccLogger.Debugf("External chaincode %s client exited", ccid) diff --git a/core/chaincode/extcc/extcc_handler_test.go b/core/chaincode/extcc/extcc_handler_test.go index 7393570c054..254a17c65dd 100644 --- a/core/chaincode/extcc/extcc_handler_test.go +++ b/core/chaincode/extcc/extcc_handler_test.go @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package extcc_test import ( + "errors" "net" "time" @@ -72,6 +73,19 @@ var _ = Describe("Extcc", func() { streamArg := shandler.HandleChaincodeStreamArgsForCall(0) Expect(streamArg).To(Not(BeNil())) }) + + It("HandleChaincodeStream returns error", func() { + ccinfo := &ccintf.ChaincodeServerInfo{ + Address: cclist.Addr().String(), + ClientConfig: comm.ClientConfig{ + KaOpts: comm.DefaultKeepaliveOptions, + DialTimeout: 10 * time.Second, + }, + } + shandler.HandleChaincodeStreamReturns(errors.New("error returned by HandleChaincodeStream")) + err := i.Stream("ccid", ccinfo, shandler) + Expect(err).To(MatchError(ContainSubstring("error handling chaincode stream for ccid"))) + }) }) Context("chaincode info incorrect", func() { var ccinfo *ccintf.ChaincodeServerInfo