Skip to content

Commit

Permalink
Merge pull request #175 from guggero/fix-rest
Browse files Browse the repository at this point in the history
server: fix REST connection
  • Loading branch information
guggero authored Nov 24, 2020
2 parents 245ddcf + 058307a commit c40b8e4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Server struct {
restProxy *http.Server
grpcListener net.Listener
restListener net.Listener
restCancel func()
macaroonService *macaroons.Service
wg sync.WaitGroup
}
Expand Down Expand Up @@ -194,8 +195,8 @@ func (s *Server) Start() error {

// We'll also create and start an accompanying proxy to serve
// clients through REST.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var ctx context.Context
ctx, s.restCancel = context.WithCancel(context.Background())
mux := proxy.NewServeMux()
proxyOpts := []grpc.DialOption{
grpc.WithTransportCredentials(*restClientCreds),
Expand Down Expand Up @@ -254,9 +255,6 @@ func (s *Server) Start() error {

log.Infof("RPC server listening on %s", s.grpcListener.Addr())
if s.restListener != nil {
s.restListener = tls.NewListener(
s.restListener, serverTLSCfg,
)
log.Infof("REST proxy listening on %s",
s.restListener.Addr())
}
Expand Down Expand Up @@ -479,6 +477,10 @@ func (s *Server) Stop() error {
shutdownErr = err
}
s.grpcServer.GracefulStop()

if s.restCancel != nil {
s.restCancel()
}
if s.restProxy != nil {
err := s.restProxy.Shutdown(context.Background())
if err != nil {
Expand Down

0 comments on commit c40b8e4

Please sign in to comment.