Skip to content

Commit

Permalink
Add error handle for Stream()
Browse files Browse the repository at this point in the history
The patchset checks the potential returned error from the stream between
peer and external chaincode.

Change-Id: I8928e64ce09d6f6a0f2f411473d645c46a1b0db5
Signed-off-by: Baohua Yang <[email protected]>
Signed-off-by: Baohua Yang <[email protected]>
  • Loading branch information
yeasy authored and denyeart committed Nov 1, 2023
1 parent 33fcbcc commit bff8b5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/chaincode/extcc/extcc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions core/chaincode/extcc/extcc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package extcc_test

import (
"errors"
"net"
"time"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bff8b5d

Please sign in to comment.