1
0
Fork 0

Close HTTP service on shutdown

master
Philip O'Toole 2 years ago
parent 53aa04158c
commit f6eefd1690

@ -170,6 +170,8 @@ func main() {
// Perform a stepdown, ignore any errors.
str.Stepdown(true)
}
httpServ.Close()
if err := str.Close(true); err != nil {
log.Printf("failed to close store: %s", err.Error())
}

@ -3,6 +3,7 @@
package http
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
@ -245,9 +246,10 @@ func ResetStats() {
// Service provides HTTP service.
type Service struct {
closeCh chan struct{}
addr string // Bind address of the HTTP service.
ln net.Listener // Service listener
httpServer http.Server
closeCh chan struct{}
addr string // Bind address of the HTTP service.
ln net.Listener // Service listener
store Store // The Raft-backed database store.
@ -304,7 +306,7 @@ func New(addr string, store Store, cluster Cluster, credentials CredentialStore)
// Start starts the service.
func (s *Service) Start() error {
server := http.Server{
s.httpServer = http.Server{
Handler: s,
}
@ -337,9 +339,9 @@ func (s *Service) Start() error {
s.DefaultQueueCap, s.DefaultQueueBatchSz, s.DefaultQueueTimeout.String())
go func() {
err := server.Serve(s.ln)
err := s.httpServer.Serve(s.ln)
if err != nil {
s.logger.Println("HTTP service Serve() returned:", err.Error())
s.logger.Println("HTTP service stopped:", err.Error())
}
}()
s.logger.Println("service listening on", s.Addr())
@ -349,8 +351,9 @@ func (s *Service) Start() error {
// Close closes the service.
func (s *Service) Close() {
s.stmtQueue.Close()
s.httpServer.Shutdown(context.Background())
s.stmtQueue.Close()
select {
case <-s.queueDone:
default:

Loading…
Cancel
Save