Skip to content

Commit

Permalink
Merge "FAB-15935 Make ConnectionTimeout configurable" into release-1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yellick authored and Gerrit Code Review committed Jul 12, 2019
2 parents bbaed63 + 92f16c0 commit f57b952
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 22 deletions.
5 changes: 4 additions & 1 deletion core/peer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ func GetServerConfig() (comm.ServerConfig, error) {
secureOptions := &comm.SecureOptions{
UseTLS: viper.GetBool("peer.tls.enabled"),
}
serverConfig := comm.ServerConfig{SecOpts: secureOptions}
serverConfig := comm.ServerConfig{
ConnectionTimeout: viper.GetDuration("peer.connectiontimeout"),
SecOpts: secureOptions,
}
if secureOptions.UseTLS {
// get the certs from the file system
serverKey, err := ioutil.ReadFile(config.GetPath("peer.tls.key.file"))
Expand Down
5 changes: 3 additions & 2 deletions core/peer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ func TestGetServerConfig(t *testing.T) {

// good config without TLS
viper.Set("peer.tls.enabled", false)
viper.Set("peer.connectiontimeout", "7s")
sc, _ := GetServerConfig()
assert.Equal(t, false, sc.SecOpts.UseTLS,
"ServerConfig.SecOpts.UseTLS should be false")
assert.Equal(t, false, sc.SecOpts.UseTLS, "ServerConfig.SecOpts.UseTLS should be false")
assert.Equal(t, sc.ConnectionTimeout, 7*time.Second, "ServerConfig.ConnectionTimeout should be 7 seconds")

// keepalive options
assert.Equal(t, comm.DefaultKeepaliveOptions, sc.KaOpts,
Expand Down
31 changes: 16 additions & 15 deletions orderer/common/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ type TopLevel struct {

// General contains config which should be common among all orderer types.
type General struct {
LedgerType string
ListenAddress string
ListenPort uint16
TLS TLS
Cluster Cluster
Keepalive Keepalive
GenesisMethod string
GenesisProfile string
SystemChannel string
GenesisFile string
Profile Profile
LocalMSPDir string
LocalMSPID string
BCCSP *bccsp.FactoryOpts
Authentication Authentication
LedgerType string
ListenAddress string
ListenPort uint16
TLS TLS
Cluster Cluster
Keepalive Keepalive
ConnectionTimeout time.Duration
GenesisMethod string
GenesisProfile string
SystemChannel string
GenesisFile string
Profile Profile
LocalMSPDir string
LocalMSPID string
BCCSP *bccsp.FactoryOpts
Authentication Authentication
}

type Cluster struct {
Expand Down
22 changes: 22 additions & 0 deletions orderer/common/localconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,25 @@ Consensus:
assert.Equal(t, foo.Foo, "bar")
assert.Equal(t, foo.Hello.World, 42)
}

func TestConnectionTimeout(t *testing.T) {
t.Run("without connection timeout overridden", func(t *testing.T) {
cleanup := configtest.SetDevFabricConfigPath(t)
defer cleanup()
cfg, err := Load()
assert.NotNil(t, cfg, "Could not load config")
assert.NoError(t, err, "Load good config returned unexpected error")
assert.Equal(t, cfg.General.ConnectionTimeout, 0*time.Second)
})

t.Run("with connection timeout overridden", func(t *testing.T) {
os.Setenv("ORDERER_GENERAL_CONNECTIONTIMEOUT", "10s")
defer os.Unsetenv("ORDERER_GENERAL_CONNECTIONTIMEOUT")
cleanup := configtest.SetDevFabricConfigPath(t)
defer cleanup()
cfg, err := Load()
assert.NotNil(t, cfg, "Could not load config")
assert.NoError(t, err, "Load good config returned unexpected error")
assert.Equal(t, cfg.General.ConnectionTimeout, 10*time.Second)
})
}
9 changes: 5 additions & 4 deletions orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,11 @@ func initializeServerConfig(conf *localconfig.TopLevel, metricsProvider metrics.
}

return comm.ServerConfig{
SecOpts: secureOpts,
KaOpts: kaOpts,
Logger: commLogger,
MetricsProvider: metricsProvider,
SecOpts: secureOpts,
KaOpts: kaOpts,
Logger: commLogger,
MetricsProvider: metricsProvider,
ConnectionTimeout: conf.General.ConnectionTimeout,
StreamInterceptors: []grpc.StreamServerInterceptor{
grpcmetrics.StreamServerInterceptor(grpcmetrics.NewStreamMetrics(metricsProvider)),
grpclogging.StreamServerInterceptor(flogging.MustGetLogger("comm.grpc.server").Zap()),
Expand Down
2 changes: 2 additions & 0 deletions orderer/common/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestInitializeProfilingService(t *testing.T) {
func TestInitializeServerConfig(t *testing.T) {
conf := &localconfig.TopLevel{
General: localconfig.General{
ConnectionTimeout: 7 * time.Second,
TLS: localconfig.TLS{
Enabled: true,
ClientAuthRequired: true,
Expand All @@ -105,6 +106,7 @@ func TestInitializeServerConfig(t *testing.T) {
assert.Equal(t, defaultOpts.ServerMinInterval, sc.KaOpts.ServerMinInterval)
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerInterval)
assert.Equal(t, time.Duration(0), sc.KaOpts.ServerTimeout)
assert.Equal(t, 7*time.Second, sc.ConnectionTimeout)
testDuration := 10 * time.Second
conf.General.Keepalive = localconfig.Keepalive{
ServerMinInterval: testDuration,
Expand Down

0 comments on commit f57b952

Please sign in to comment.