@@ -11,7 +11,6 @@ import (
1111 "github.com/cockroachdb/errors"
1212 "github.com/cockroachdb/errors/oserror"
1313 "github.com/data-preservation-programs/singularity/model"
14- "github.com/data-preservation-programs/singularity/service"
1514 "github.com/data-preservation-programs/singularity/storagesystem"
1615 "github.com/data-preservation-programs/singularity/store"
1716 "github.com/data-preservation-programs/singularity/util"
@@ -49,7 +48,7 @@ func (*HTTPServer) Name() string {
4948// - A Done channel slice that are closed when the server has stopped.
5049// - A Fail channel that receives an error if the server fails to start or stop.
5150// - An error if the server fails to start.
52- func (s * HTTPServer ) Start (ctx context.Context ) ([]service. Done , service. Fail , error ) {
51+ func (s * HTTPServer ) Start (ctx context.Context , exitErr chan <- error ) error {
5352 e := echo .New ()
5453 e .Use (middleware .GzipWithConfig (middleware.GzipConfig {}))
5554 e .Use (
@@ -98,27 +97,35 @@ func (s *HTTPServer) Start(ctx context.Context) ([]service.Done, service.Fail, e
9897 e .GET ("/health" , func (c echo.Context ) error {
9998 return c .String (http .StatusOK , "ok" )
10099 })
101- done := make (chan struct {})
102- fail := make (chan error )
100+
101+ forceShutdown := make (chan struct {})
102+ shutdownErr := make (chan error , 1 )
103+
103104 go func () {
104105 err := e .Start (s .bind )
105- if err != nil {
106- select {
107- case <- ctx .Done ():
108- case fail <- err :
106+ if errors .Is (err , http .ErrServerClosed ) {
107+ err = nil
108+ }
109+ close (forceShutdown )
110+ closeErr := <- shutdownErr
111+ if exitErr != nil {
112+ if err == nil {
113+ err = closeErr
109114 }
115+ exitErr <- err
110116 }
111117 }()
118+
112119 go func () {
113- defer close (done )
114- <- ctx .Done ()
115- //nolint:contextcheck
116- err := e .Shutdown (context .Background ())
117- if err != nil {
118- fail <- err
120+ select {
121+ case <- ctx .Done ():
122+ case <- forceShutdown :
119123 }
124+ //nolint:contextcheck
125+ shutdownErr <- e .Shutdown (context .Background ())
120126 }()
121- return []service.Done {done }, fail , nil
127+
128+ return nil
122129}
123130
124131func getPieceMetadata (ctx context.Context , db * gorm.DB , car model.Car ) (* PieceMetadata , error ) {
0 commit comments