Skip to content
  • Alex Ellis (VMware)'s avatar
    de2c74fc
    Add feature for graceful shutdown of HTTP server · de2c74fc
    Alex Ellis (VMware) authored
    If the watchdog is sent SIGTERM from an external process then it
    should stop accepting new connections and attempt to finish the
    work in progress. This change makes use of the new ability in Go
    1.9 and onwards to cancel a HTTP server gracefully.
    
    The write_timeout duration is used as a grace period to allow all
    in-flight requests to complete. The pattern is taken directly from
    the offical example in the Golang documentation. [1]
    
    Further tuning and testing may be needed for Windows containers which
    have a different set of signals for closing work. This change aims
    to cover the majority use-case for Linux containers.
    
    The HTTP health-check is also invalidated by creating an and
    expression with the existing lock file.
    
    Tested with Kubernetes by deploying a custom watchdog and the
    fprocess of `env`. Log message was observed when scaling down and
    connections stopped being accepted on terminating replica.
    
    Also corrects some typos from previous PR.
    
    [1] https://golang.org/pkg/net/http/#Server.Shutdown
    
    
    
    Signed-off-by: default avatarAlex Ellis (VMware) <alexellis2@gmail.com>
    de2c74fc
    Add feature for graceful shutdown of HTTP server
    Alex Ellis (VMware) authored
    If the watchdog is sent SIGTERM from an external process then it
    should stop accepting new connections and attempt to finish the
    work in progress. This change makes use of the new ability in Go
    1.9 and onwards to cancel a HTTP server gracefully.
    
    The write_timeout duration is used as a grace period to allow all
    in-flight requests to complete. The pattern is taken directly from
    the offical example in the Golang documentation. [1]
    
    Further tuning and testing may be needed for Windows containers which
    have a different set of signals for closing work. This change aims
    to cover the majority use-case for Linux containers.
    
    The HTTP health-check is also invalidated by creating an and
    expression with the existing lock file.
    
    Tested with Kubernetes by deploying a custom watchdog and the
    fprocess of `env`. Log message was observed when scaling down and
    connections stopped being accepted on terminating replica.
    
    Also corrects some typos from previous PR.
    
    [1] https://golang.org/pkg/net/http/#Server.Shutdown
    
    
    
    Signed-off-by: default avatarAlex Ellis (VMware) <alexellis2@gmail.com>
Loading