Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed Apr 19, 2024
1 parent 4b1ef00 commit 70d30ec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ func (s *Server) Start() error {
}

// Implementing graceful shutdown - if an interrupt signal is received, stop listening on the port
idleConnsClosed := make(chan struct{})
idleConnClosedChan := make(chan struct{})

go func() {
defer close(idleConnClosedChan)

sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
<-sigint
Expand All @@ -133,13 +135,12 @@ func (s *Server) Start() error {
// Error from closing listener(s), or context timeout:
log.Printf("HTTP server Shutdown: %v", err)
}
close(idleConnsClosed)
}()

if err := server.Serve(tcpListener); err != nil && !errors.Is(err, http.ErrServerClosed) {
return fmt.Errorf("server serve: %w", err)
}
<-idleConnsClosed
<-idleConnClosedChan

return nil
}

0 comments on commit 70d30ec

Please sign in to comment.