Skip to content

Commit

Permalink
[FAB-8571] timeout refactoring in chclient,txnhandler
Browse files Browse the repository at this point in the history
Putting back timeout logic removed from txnHandler,
but using 'context.done' instead.

Change-Id: I67c6178c6797ea82d13d457d72eb0a528183487b
Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Mar 15, 2018
1 parent 6b54b4c commit 5346c29
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/client/channel/chclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/status"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -146,6 +147,9 @@ func (cc *Client) InvokeHandler(handler invoke.Handler, request Request, options
select {
case <-complete:
return Response(requestContext.Response), requestContext.Error
case <-reqCtx.Done():
return Response{}, status.New(status.ClientStatus, status.Timeout.ToInt32(),
"request timed out", nil)
}
}

Expand Down Expand Up @@ -216,6 +220,7 @@ func (cc *Client) prepareHandlerContexts(reqCtx reqContext.Context, request Requ
Opts: invoke.Opts(o),
Response: invoke.Response{},
RetryHandler: retry.New(o.Retry),
Ctx: reqCtx,
}

return requestContext, clientContext, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/client/channel/invoke/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ type RequestContext struct {
Response Response
Error error
RetryHandler retry.Handler
Ctx reqContext.Context
}
3 changes: 3 additions & 0 deletions pkg/client/channel/invoke/txnhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func (c *CommitTxHandler) Handle(requestContext *RequestContext, clientContext *
requestContext.Error = status.New(status.EventServerStatus, int32(txStatus.TxValidationCode), "received invalid transaction", nil)
return
}
case <-requestContext.Ctx.Done():
requestContext.Error = errors.New("Execute didn't receive block event")
return
}

//Delegate to next step if any
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/channel/invoke/txnhandler_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 invoke

import (
reqContext "context"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -212,6 +213,7 @@ func prepareRequestContext(request Request, opts Opts, t *testing.T) *RequestCon
requestContext := &RequestContext{Request: request,
Opts: opts,
Response: Response{},
Ctx: reqContext.Background(),
}

requestContext.Opts.Timeouts = make(map[core.TimeoutType]time.Duration)
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ func (rc *Client) sendCCProposal(reqCtx reqContext.Context, ccProposalType chain
return nil
}
return status.New(status.EventServerStatus, int32(txStatus.TxValidationCode), "instantiateOrUpgradeCC failed", nil)
case <-reqCtx.Done():
return errors.New("instantiateOrUpgradeCC timeout")
}

}
Expand Down

0 comments on commit 5346c29

Please sign in to comment.