Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry pick #813, refine grpc graceful stop #825

Merged
merged 3 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ func QueryLatestTsFromPD(tiStore kv.Storage) (int64, error) {
return int64(version.Ver), nil
}

// WaitUntilTimeout creates a goroutine to run fn, and then gives up waiting for the goroutine to exit When it timeouts
func WaitUntilTimeout(name string, fn func(), timeout time.Duration) {
exited := make(chan struct{})
go func() {
defer func() {
log.Info("goroutine %s exit by itself (with GoAndAbortGoroutine help)", name)
close(exited)
}()
fn()
}()

select {
case <-time.After(timeout):
log.Info("abort goroutine %s (with GoAndAbortGoroutine help)", name)
case <-exited:
}
}

// StrictDecodeFile decodes the toml file strictly. If any item in confFile file is not mapped
// into the Config struct, issue an error and stop the server from starting.
func StrictDecodeFile(path, component string, cfg interface{}) error {
Expand Down
6 changes: 4 additions & 2 deletions pump/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,10 @@ func (s *Server) Close() {
// PullBinlogs should be stopped after commitStatus
close(s.pullClose)
// stop the gRPC server
s.gs.GracefulStop()
log.Info("grpc is stopped")
util.WaitUntilTimeout("grpc_server.GracefulStop", func() {
s.gs.GracefulStop()
log.Info("grpc is stopped")
}, 10*time.Second)

if err := s.storage.Close(); err != nil {
log.Errorf("close storage error %v", errors.ErrorStack(err))
Expand Down