Add enforced timeout to Raft join.

This commit is contained in:
gram-signal 2024-11-14 12:16:03 -08:00 committed by GitHub
parent fc6985be3e
commit dece3bd899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 8 deletions

View File

@ -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",

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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)