Add enforced timeout to Raft join.
This commit is contained in:
parent
fc6985be3e
commit
dece3bd899
@ -114,6 +114,7 @@ func Default() *Config {
|
||||
EnvStatsPollDuration: 0,
|
||||
RefreshAttestationDuration: time.Minute * 10,
|
||||
EnclaveConcurrency: util.Min(runtime.NumCPU(), 64),
|
||||
InitialJoinDuration: time.Hour,
|
||||
},
|
||||
Redis: RedisConfig{
|
||||
Name: "test",
|
||||
|
||||
@ -21,6 +21,8 @@ type RaftHostConfig struct {
|
||||
EnvStatsPollDuration time.Duration `yaml:"envStatsPollDuration"`
|
||||
// max number of in-flight enclave calls
|
||||
EnclaveConcurrency int `yaml:"enclaveConcurrency"`
|
||||
// timeout for intitial raft Joining attempt
|
||||
InitialJoinDuration time.Duration `yaml:"initialJoinDuration"`
|
||||
}
|
||||
|
||||
func (r *RaftHostConfig) validate() []string {
|
||||
|
||||
@ -132,14 +132,23 @@ func (r *RaftManager) CreateOrJoin(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return errors.New("failed to fetch raft peers")
|
||||
}
|
||||
if raftPeer == r.me {
|
||||
logger.Infow("attempting to create a new raft group")
|
||||
if err := r.createRaft(); err != nil {
|
||||
return err
|
||||
joined := make(chan error)
|
||||
|
||||
go func() {
|
||||
if raftPeer == r.me {
|
||||
logger.Infow("attempting to create a new raft group")
|
||||
joined <- r.createRaft()
|
||||
} else {
|
||||
logger.Infow("attempting to join existing raft group", "peerID", raftPeer)
|
||||
joined <- r.joinExistingRaftPeer(raftPeer)
|
||||
}
|
||||
} else {
|
||||
logger.Infow("attempting to join existing raft group", "peerID", raftPeer)
|
||||
if err := r.joinExistingRaftPeer(raftPeer); err != nil {
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case err := <-joined:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func Start(ctx context.Context, hconfig *config.Config, authenticator auth.Auth,
|
||||
|
||||
// wait until we successfully create a raft group or join an existing one
|
||||
raftManager := raftmanager.New(nodeID, dispatcher, peerDB, hconfig)
|
||||
joinCtx, joinCancel := context.WithTimeout(ctx, time.Minute)
|
||||
joinCtx, joinCancel := context.WithTimeout(ctx, hconfig.Raft.InitialJoinDuration)
|
||||
defer joinCancel()
|
||||
if err := raftManager.CreateOrJoin(joinCtx); err != nil {
|
||||
return fmt.Errorf("failure to join raft : %v", err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user