skovtunenko/graterm

Awesome-go: documentation review comments

skovtunenko opened this issue · 2 comments

  • Update README.md to add more details regarding hooks with the same Order -- what would be the effect?
  • Reformat code snippets in README.md to be vertical-oriented instead of horizontal-oriented.
  • In README.md, choose fewer indentation spaces.
  • Fix code indentation in this line: // ..........
  • Try to refactor this function into smaller ones:

    graterm/terminator.go

    Lines 118 to 176 in 9ba2fb9

    func (t *Terminator) waitShutdown(appCtx context.Context) {
    defer t.wg.Done()
    <-appCtx.Done() // Block until application context is done (most likely, when the registered os.Signal will be received)
    t.hooksMx.Lock()
    defer t.hooksMx.Unlock()
    order := make([]int, 0, len(t.hooks))
    for k := range t.hooks {
    order = append(order, int(k))
    }
    sort.Ints(order)
    for _, o := range order {
    o := o
    runWg := sync.WaitGroup{}
    for _, c := range t.hooks[Order(o)] {
    runWg.Add(1)
    go func(f Hook) {
    defer runWg.Done()
    ctx, cancel := context.WithTimeout(context.Background(), f.timeout)
    defer cancel()
    var execDuration time.Duration
    go func() {
    currentTime := time.Now()
    defer func() {
    defer cancel()
    execDuration = time.Since(currentTime)
    if err := recover(); err != nil {
    t.log.Printf("registered hook panicked after %v for %v, recovered: %+v", execDuration, &f, err)
    }
    }()
    f.hookFunc(ctx)
    }()
    <-ctx.Done() // block until the hookFunc is over OR timeout has been expired
    switch err := ctx.Err(); {
    case errors.Is(err, context.DeadlineExceeded):
    t.log.Printf("registered hook timed out after %v for %v", f.timeout, &f)
    case errors.Is(err, context.Canceled):
    t.log.Printf("registered hook finished termination in %v (out of maximum %v) for %v", execDuration, f.timeout, &f)
    }
    }(c)
    }
    runWg.Wait()
    }
    }
  • In "Integration with HTTP server" doc section, fix indentation for ReadHeaderTimeout
  • Remove HTTP server config to address Slowris attack (it is unnecessary details)
  • Add "AwesomeGo" label to the repo.

Add "Awesome Go" label to the repo: #86

Remove HTTP server config to address Slowris attack (it is unnecessary details): #87