GithubHelp home page GithubHelp logo

skovtunenko / graterm Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 2.0 77 KB

Provides primitives to perform ordered GRAceful TERmination for Golang applications

License: MIT License

Go 97.40% Makefile 2.60%
graceful-shutdown termination graceful-degradation graceful-restart-process graceful-stop gracefull gracefully shutdown shutdown-helper shutdown-hook

graterm's Issues

Add more documentation for `WithName()`method and `Hook` type

  • Add more documentation for WithName()method . It is now not clear when to use this method
  • And Hook type a detailed description
  • Document, what will happen if the passed root context (to the Terminator constructor) will be canceled.
  • Document that ctx that will be passed into actual termination hook is used only for cancellation signaling

Awesome-go: documentation review 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.