Skip to content

Commit e1fff80

Browse files
committed
[FAB-11487] always propagate send fail errors
Errors encountered while sending a message from the peer to chaincode were not handled consistently. This CR adopts the philosophy that send failures should be treated consistently. Change-Id: I49893e7db0376c0b78d1f654c7dc94e6eeabb38d Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent c8a8261 commit e1fff80

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

core/chaincode/handler.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (h *Handler) HandleTransaction(msg *pb.ChaincodeMessage, delegate handleFun
249249

250250
chaincodeLogger.Debugf("[%s] Completed %s. Sending %s", shorttxid(msg.Txid), msg.Type, resp.Type)
251251
h.ActiveTransactions.Remove(msg.ChannelId, msg.Txid)
252-
h.serialSendAsync(resp, false)
252+
h.serialSendAsync(resp)
253253
}
254254

255255
func shorttxid(txid string) string {
@@ -303,17 +303,20 @@ func (h *Handler) serialSend(msg *pb.ChaincodeMessage) error {
303303
// can be nonblocking. Only errors need to be handled and these are handled by
304304
// communication on supplied error channel. A typical use will be a non-blocking or
305305
// nil channel
306-
func (h *Handler) serialSendAsync(msg *pb.ChaincodeMessage, sendErr bool) {
306+
func (h *Handler) serialSendAsync(msg *pb.ChaincodeMessage) {
307307
go func() {
308308
if err := h.serialSend(msg); err != nil {
309-
if sendErr {
310-
// provide an error response to the caller
311-
resp := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_ERROR, Payload: []byte(err.Error()), Txid: msg.Txid, ChannelId: msg.ChannelId}
312-
h.Notify(resp)
313-
314-
// provide an error response to the caller
315-
h.errChan <- err
309+
// provide an error response to the caller
310+
resp := &pb.ChaincodeMessage{
311+
Type: pb.ChaincodeMessage_ERROR,
312+
Payload: []byte(err.Error()),
313+
Txid: msg.Txid,
314+
ChannelId: msg.ChannelId,
316315
}
316+
h.Notify(resp)
317+
318+
// surface send error to stream processing
319+
h.errChan <- err
317320
}
318321
}()
319322
}
@@ -411,7 +414,7 @@ func (h *Handler) ProcessStream(stream ccintf.ChaincodeStream) error {
411414
case <-keepaliveCh:
412415
// if no error message from serialSend, KEEPALIVE happy, and don't care about error
413416
// (maybe it'll work later)
414-
h.serialSendAsync(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_KEEPALIVE}, false)
417+
h.serialSendAsync(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_KEEPALIVE})
415418
continue
416419
}
417420
}
@@ -918,7 +921,7 @@ func (h *Handler) Execute(txParams *ccprovider.TransactionParams, cccid *ccprovi
918921
return nil, err
919922
}
920923

921-
h.serialSendAsync(msg, true)
924+
h.serialSendAsync(msg)
922925

923926
var ccresp *pb.ChaincodeMessage
924927
select {

0 commit comments

Comments
 (0)