Skip to content

Commit d1a8a58

Browse files
authored
implement graceful shutdown (dapr#260)
Signed-off-by: Naveen Ramanathan <nramanathan@infoblox.com>
1 parent 3650784 commit d1a8a58

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

service/common/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type Service interface {
4141
Start() error
4242
// Stop stops the previously started service.
4343
Stop() error
44+
// Gracefully stops the previous started service
45+
GracefulStop() error
4446
}
4547

4648
type (

service/grpc/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Server struct {
6565
topicRegistrar internal.TopicRegistrar
6666
bindingHandlers map[string]common.BindingInvocationHandler
6767
authToken string
68+
grpcServer *grpc.Server
6869
}
6970

7071
func (s *Server) RegisterActorImplFactory(f actor.Factory, opts ...config.Option) {
@@ -75,10 +76,16 @@ func (s *Server) RegisterActorImplFactory(f actor.Factory, opts ...config.Option
7576
func (s *Server) Start() error {
7677
gs := grpc.NewServer()
7778
pb.RegisterAppCallbackServer(gs, s)
79+
s.grpcServer = gs
7880
return gs.Serve(s.listener)
7981
}
8082

8183
// Stop stops the previously started service.
8284
func (s *Server) Stop() error {
8385
return s.listener.Close()
8486
}
87+
88+
func (s *Server) GracefulStop() error {
89+
s.grpcServer.GracefulStop()
90+
return nil
91+
}

service/http/service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (s *Server) Stop() error {
8181
return s.httpServer.Shutdown(ctxShutDown)
8282
}
8383

84+
func (s *Server) GracefulStop() error {
85+
return s.Stop()
86+
}
87+
8488
func setOptions(w http.ResponseWriter, r *http.Request) {
8589
w.Header().Set("Access-Control-Allow-Origin", "*")
8690
w.Header().Set("Access-Control-Allow-Methods", "POST,OPTIONS")

0 commit comments

Comments
 (0)