~egtann/srp

747923b2fa94a2ab2ad0fbb80ff7b5e38a854599 — Evan Tann 3 years ago ad66826
remove shutdown logic
2 files changed, 2 insertions(+), 17 deletions(-)

M cmd/srp/main.go
M proxy.go
M cmd/srp/main.go => cmd/srp/main.go +2 -7
@@ 84,7 84,7 @@ func main() {
	sighupCh := make(chan bool)
	go hotReloadConfig(*config, proxy, sighupCh)
	go checkHealth(proxy, sighupCh)
	gracefulRestart(srv, proxy, timeout)
	gracefulRestart(srv, timeout)
}

// Logger implements the srp.Logger interface.


@@ 137,18 137,13 @@ func hotReloadConfig(
// received, it stops accepting new connections and allows all existing
// connections up to 10 seconds to complete. If connections do not shut down in
// time, this exits with 1.
func gracefulRestart(
	srv *http.Server,
	proxy *srp.ReverseProxy,
	timeout time.Duration,
) {
func gracefulRestart(srv *http.Server, timeout time.Duration) {
	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
	<-stop
	log.Println("shutting down...")
	ctx, cancel := context.WithTimeout(context.Background(), timeout)
	defer cancel()
	proxy.Shutdown()
	if err := srv.Shutdown(ctx); err != nil {
		log.Println("failed to shutdown server gracefully", err)
		os.Exit(1)

M proxy.go => proxy.go +0 -10
@@ 26,7 26,6 @@ type ReverseProxy struct {
	resultCh chan *healthCheck
	mu       sync.RWMutex
	log      Logger
	shutdown bool
}

// Registry maps hosts to backends with other helpful info, such as


@@ 146,9 145,6 @@ func (r *ReverseProxy) CheckHealth() {
	}
	go func() {
		for _, check := range checks {
			if r.shutdown {
				return
			}
			r.jobCh <- check
		}
	}()


@@ 174,12 170,6 @@ func (r *ReverseProxy) UpdateRegistry(reg Registry) {
	r.rp.Transport = newTransport(reg)
}

// Shutdown stops future healthchecks from running.
func (r *ReverseProxy) Shutdown() {
	r.shutdown = true
	close(r.jobCh)
}

func ping(job *healthCheck) error {
	target := "http://" + job.ip + job.healthPath
	req, err := http.NewRequest("GET", target, nil)