Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 5346c29

Browse files
committed
[FAB-8571] timeout refactoring in chclient,txnhandler
Putting back timeout logic removed from txnHandler, but using 'context.done' instead. Change-Id: I67c6178c6797ea82d13d457d72eb0a528183487b Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
1 parent 6b54b4c commit 5346c29

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

pkg/client/channel/chclient.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
2121
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
2222
"github.com/hyperledger/fabric-sdk-go/pkg/errors/retry"
23+
"github.com/hyperledger/fabric-sdk-go/pkg/errors/status"
2324
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
2425
"github.com/pkg/errors"
2526
)
@@ -146,6 +147,9 @@ func (cc *Client) InvokeHandler(handler invoke.Handler, request Request, options
146147
select {
147148
case <-complete:
148149
return Response(requestContext.Response), requestContext.Error
150+
case <-reqCtx.Done():
151+
return Response{}, status.New(status.ClientStatus, status.Timeout.ToInt32(),
152+
"request timed out", nil)
149153
}
150154
}
151155

@@ -216,6 +220,7 @@ func (cc *Client) prepareHandlerContexts(reqCtx reqContext.Context, request Requ
216220
Opts: invoke.Opts(o),
217221
Response: invoke.Response{},
218222
RetryHandler: retry.New(o.Retry),
223+
Ctx: reqCtx,
219224
}
220225

221226
return requestContext, clientContext, nil

pkg/client/channel/invoke/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ type RequestContext struct {
6464
Response Response
6565
Error error
6666
RetryHandler retry.Handler
67+
Ctx reqContext.Context
6768
}

pkg/client/channel/invoke/txnhandler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func (c *CommitTxHandler) Handle(requestContext *RequestContext, clientContext *
162162
requestContext.Error = status.New(status.EventServerStatus, int32(txStatus.TxValidationCode), "received invalid transaction", nil)
163163
return
164164
}
165+
case <-requestContext.Ctx.Done():
166+
requestContext.Error = errors.New("Execute didn't receive block event")
167+
return
165168
}
166169

167170
//Delegate to next step if any

pkg/client/channel/invoke/txnhandler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package invoke
88

99
import (
10+
reqContext "context"
1011
"strings"
1112
"testing"
1213
"time"
@@ -212,6 +213,7 @@ func prepareRequestContext(request Request, opts Opts, t *testing.T) *RequestCon
212213
requestContext := &RequestContext{Request: request,
213214
Opts: opts,
214215
Response: Response{},
216+
Ctx: reqContext.Background(),
215217
}
216218

217219
requestContext.Opts.Timeouts = make(map[core.TimeoutType]time.Duration)

pkg/client/resmgmt/resmgmt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ func (rc *Client) sendCCProposal(reqCtx reqContext.Context, ccProposalType chain
603603
return nil
604604
}
605605
return status.New(status.EventServerStatus, int32(txStatus.TxValidationCode), "instantiateOrUpgradeCC failed", nil)
606+
case <-reqCtx.Done():
607+
return errors.New("instantiateOrUpgradeCC timeout")
606608
}
607609

608610
}

0 commit comments

Comments
 (0)