Skip to content

Commit

Permalink
fix http listener and dont ignore errors from http listener (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke authored Apr 3, 2024
1 parent 39487b8 commit f35271f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/httpserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Server) Listen(ctx context.Context) error {

s.server.BaseContext = func(_ net.Listener) context.Context { return ctx }

var errCh chan error
errCh := make(chan error)

if s.conf.TLS {
s.logger.Info(fmt.Sprintf(
Expand All @@ -70,11 +70,13 @@ func (s *Server) Listen(ctx context.Context) error {
))

go func() {
errCh <- s.server.ListenAndServeTLS("", "")
errCh <- s.server.ListenAndServe()
}()
}

select {
case err := <-errCh:
return fmt.Errorf("error http %s listening: %w", s.name, err)
case <-ctx.Done():
s.logger.Info(fmt.Sprintf("start graceful shutdown of http %s listener", s.name))

Expand All @@ -85,8 +87,6 @@ func (s *Server) Listen(ctx context.Context) error {
}

s.logger.Info(fmt.Sprintf("http %s listener successfully terminated", s.name))
case err := <-errCh:
return fmt.Errorf("error http %s listening: %w", s.name, err)
}

return nil
Expand Down

0 comments on commit f35271f

Please sign in to comment.