Skip to content

Commit

Permalink
Don't call grpc stop before server initialized
Browse files Browse the repository at this point in the history
When receiving a stop signal, it is possible that the GRPC server has
not yet been iniitialized. Verify that is has been before trying to stop
the server.

(cherry picked from commit 0545aaf)
  • Loading branch information
codenrhoden committed Mar 25, 2020
1 parent 9407f5f commit f742530
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gocsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ func (sp *StoragePlugin) Serve(ctx context.Context, lis net.Listener) error {
// errors.
func (sp *StoragePlugin) Stop(ctx context.Context) {
sp.stopOnce.Do(func() {
sp.server.Stop()
if sp.server != nil {
sp.server.Stop()
}
log.Info("stopped")
})
}
Expand All @@ -330,7 +332,9 @@ func (sp *StoragePlugin) Stop(ctx context.Context) {
// pending RPCs are finished.
func (sp *StoragePlugin) GracefulStop(ctx context.Context) {
sp.stopOnce.Do(func() {
sp.server.GracefulStop()
if sp.server != nil {
sp.server.GracefulStop()
}
log.Info("gracefully stopped")
})
}
Expand Down

0 comments on commit f742530

Please sign in to comment.