Skip to content

Commit

Permalink
skipper: use queuelistener for HTTPS
Browse files Browse the repository at this point in the history
PR #1866 implemented HTTPS graceful shutdown but did not use queuelistener.

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov committed Jul 12, 2023
1 parent 3cffdd6 commit c885991
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,6 @@ func (o *Options) tlsConfig(cr *certregistry.CertRegistry) (*tls.Config, error)
}

func listen(o *Options, address string, mtr metrics.Metrics) (net.Listener, error) {
if address == "" {
address = ":http"
}

if !o.EnableTCPQueue {
return net.Listen("tcp", address)
Expand Down Expand Up @@ -1203,9 +1200,19 @@ func listenAndServeQuit(
if err != nil {
return err
}
serveTLS := tlsConfig != nil

address := o.Address
if address == "" {
if serveTLS {
address = ":https"
} else {
address = ":http"
}
}

srv := &http.Server{
Addr: o.Address,
Addr: address,
TLSConfig: tlsConfig,
Handler: proxy,
ReadTimeout: o.ReadTimeoutServer,
Expand All @@ -1223,6 +1230,13 @@ func listenAndServeQuit(
}
}

log.Infof("Listen on %v", address)

l, err := listen(o, address, mtr)
if err != nil {
return err
}

// making idleConnsCH and sigs optional parameters is required to be able to tear down a server
// from the tests
if idleConnsCH == nil {
Expand All @@ -1248,16 +1262,14 @@ func listenAndServeQuit(
close(idleConnsCH)
}()

log.Infof("proxy listener on %v", o.Address)

if srv.TLSConfig != nil {
if serveTLS {
if o.InsecureAddress != "" {
log.Infof("insecure listener on %v", o.InsecureAddress)
log.Infof("Insecure listener on %v", o.InsecureAddress)

go func() {
l, err := listen(o, o.InsecureAddress, mtr)
if err != nil {
log.Errorf("Failed to start insecure listener on %s: %v", o.Address, err)
log.Errorf("Failed to start insecure listener on %s: %v", o.InsecureAddress, err)
}

if err := srv.Serve(l); err != http.ErrServerClosed {
Expand All @@ -1266,16 +1278,12 @@ func listenAndServeQuit(
}()
}

if err := srv.ListenAndServeTLS("", ""); err != http.ErrServerClosed {
log.Errorf("ListenAndServeTLS failed: %v", err)
if err := srv.ServeTLS(l, "", ""); err != http.ErrServerClosed {
log.Errorf("ServeTLS failed: %v", err)
return err
}
} else {
log.Infof("TLS settings not found, defaulting to HTTP")
l, err := listen(o, o.Address, mtr)
if err != nil {
return err
}

if err := srv.Serve(l); err != http.ErrServerClosed {
log.Errorf("Serve failed: %v", err)
Expand Down

0 comments on commit c885991

Please sign in to comment.