Skip to content

Commit

Permalink
Merge pull request #227 from nspcc-dev/fast-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Jun 27, 2024
2 parents b482739 + e77151d commit da33f93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/neofs-rest-gw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func main() {
go neofsAPI.StartCallback()

<-ctx.Done()
neofsAPI.StopServices()
if err = e.Shutdown(ctx); err != nil {
logger.Fatal("shutdown http and https", zap.Error(err))
}
Expand Down
19 changes: 19 additions & 0 deletions handlers/api.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package handlers

import (
"context"
"errors"
"fmt"
"strings"
"sync"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -153,3 +155,20 @@ func (a *RestAPI) RunServices() {
go a.pprofService.Start()
go a.prometheusService.Start()
}

// StopServices stops all running services with configured timeout.
func (a *RestAPI) StopServices() {
ctx, cancel := context.WithTimeout(context.Background(), a.serviceShutdownTimeout)
defer cancel()
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
a.pprofService.ShutDown(ctx)
}()
go func() {
defer wg.Done()
a.prometheusService.ShutDown(ctx)
}()
wg.Wait()
}

0 comments on commit da33f93

Please sign in to comment.