Skip to content

Commit

Permalink
[FAB-8627] Add clientChannel timeout conf
Browse files Browse the repository at this point in the history
	timeout logic for the client handler is:
	1. get timeout from options
	2. if empty, then get timeout from config
	3. if empty, then use default timeout set in 'defaultHandlerTimeout'

	Also exposed Timeout function in the config interface
	The client can now use either TimeoutOrDefault (with preset default
	if type is not found in the config) or call Timeout (default is 0 if
	type is not found)

Change-Id: I05bca13fdae23af006a9291c737b7b4b2ee8d0d2
Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Mar 5, 2018
1 parent 4b576fd commit c5e1bc3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
9 changes: 7 additions & 2 deletions pkg/client/channel/chclient.go
Expand Up @@ -26,7 +26,7 @@ import (
var logger = logging.NewLogger("fabric_sdk_go")

const (
defaultHandlerTimeout = time.Second * 10
defaultHandlerTimeout = time.Second * 180
)

// Client enables access to a channel on a Fabric network.
Expand Down Expand Up @@ -172,7 +172,12 @@ func (cc *Client) prepareHandlerContexts(request Request, o opts) (*invoke.Reque
}

if requestContext.Opts.Timeout == 0 {
requestContext.Opts.Timeout = defaultHandlerTimeout
to := cc.context.Config().Timeout(core.Execute)
if to == 0 {
requestContext.Opts.Timeout = defaultHandlerTimeout
} else {
requestContext.Opts.Timeout = to
}
}

return requestContext, clientContext, nil
Expand Down
12 changes: 12 additions & 0 deletions pkg/context/api/core/mocks/mockcoreapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/context/api/core/provider.go
Expand Up @@ -23,6 +23,7 @@ type Config interface {
CAClientCertPem(org string) (string, error)
CAClientCertPath(org string) (string, error)
TimeoutOrDefault(TimeoutType) time.Duration
Timeout(TimeoutType) time.Duration
MspID(org string) (string, error)
PeerMspID(name string) (string, error)
OrderersConfig() ([]OrdererConfig, error)
Expand Down
19 changes: 15 additions & 4 deletions pkg/core/config/config.go
Expand Up @@ -440,8 +440,22 @@ func (c *Config) CAClientCertPem(org string) (string, error) {
return ca.TLSCACerts.Client.Cert.Pem, nil
}

// TimeoutOrDefault reads connection timeouts for the given connection type
// TimeoutOrDefault reads connection timeouts for the given timeout type, if not found, defaultTimeout is returned
func (c *Config) TimeoutOrDefault(conn core.TimeoutType) time.Duration {
timeout := c.getTimeout(conn)
if timeout == 0 {
timeout = defaultTimeout
}

return timeout
}

// Timeout reads connection timeouts for the given timeout type, the default is 0 if type is not found in config
func (c *Config) Timeout(conn core.TimeoutType) time.Duration {
return c.getTimeout(conn)
}

func (c *Config) getTimeout(conn core.TimeoutType) time.Duration {
var timeout time.Duration
switch conn {
case core.Endorser:
Expand Down Expand Up @@ -471,9 +485,6 @@ func (c *Config) TimeoutOrDefault(conn core.TimeoutType) time.Duration {
timeout = defaultConnIdleTimeout
}
}
if timeout == 0 {
timeout = defaultTimeout
}

return timeout
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/config/testdata/config_test_pem.yaml
Expand Up @@ -48,7 +48,7 @@ client:
timeout:
connection: 3s
queryResponse: 45s
executeTxResponse: 30s
executeTxResponse: 60s
discovery:
greylistExpiry: 5s
eventService:
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/config/testdata/template/config.yaml
Expand Up @@ -49,7 +49,7 @@ client:
timeout:
connection: 3s
queryResponse: 20s
executeTxResponse: 30s
executeTxResponse: 60s
discovery:
greylistExpiry: 5s
eventService:
Expand Down
5 changes: 5 additions & 0 deletions pkg/core/identitymgr/mocks/mockconfig.go
Expand Up @@ -77,6 +77,11 @@ func (c *MockConfig) TimeoutOrDefault(core.TimeoutType) time.Duration {
return 0
}

//Timeout not implemented
func (c *MockConfig) Timeout(core.TimeoutType) time.Duration {
return 0
}

// NetworkPeers returns the mock network peers configuration
func (c *MockConfig) NetworkPeers() ([]core.NetworkPeer, error) {
return nil, nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/fab/mocks/mockconfig.go
Expand Up @@ -105,6 +105,11 @@ func (c *MockConfig) TimeoutOrDefault(arg config.TimeoutType) time.Duration {
return time.Second * 5
}

//Timeout not implemented
func (c *MockConfig) Timeout(arg config.TimeoutType) time.Duration {
return time.Second * 10
}

// PeersConfig Retrieves the fabric peers from the config file provided
func (c *MockConfig) PeersConfig(org string) ([]config.PeerConfig, error) {
return nil, nil
Expand Down

0 comments on commit c5e1bc3

Please sign in to comment.