diff --git a/src/process.go b/src/process.go index a19236cdd25b76451fc250fc15e8f6f934476130..948387c8af79e6067581cf30d41f6503dd8e2a76 100644 --- a/src/process.go +++ b/src/process.go @@ -21,6 +21,7 @@ import ( "gitee.com/go-libs/log" "github.com/google/uuid" "sync" + "sync/atomic" "time" ) @@ -94,6 +95,7 @@ type ( ctx context.Context children map[string]Process parent Process + retryCount int32 started, quited, prevent bool } ) @@ -284,20 +286,26 @@ func (o *process) Start(ctx context.Context) (err error) { // Start // process providers. for { - // Return - // by parent context cancelled. + // Return by parent context cancelled. if ctx.Err() != nil { return } - // Return - // by stop signal. + // Return by stop signal. if o.quited { return } - // Reset - // current process context. + // Sleep for a while for too many restart. + if retry := atomic.AddInt32(&o.retryCount, 1); retry > 3 { + time.Sleep(time.Second) + + if ctx.Err() != nil { + return + } + } + + // Reset current process context. o.mu.Lock() o.ctx, o.cancel = context.WithCancel(ctx) o.mu.Unlock()