Close GlobalServiceDoneCh when quitting (#7322)

This change allows indefinitely running go-routines to cleanup
gracefully.

This channel is now closed at the beginning of each test so that
long-running go-routines quit and a new one is assigned.
master
Aditya Manthramurthy 6 years ago committed by kannappanr
parent f7611bcd48
commit e8e9cd3e74
  1. 2
      cmd/service.go
  2. 3
      cmd/signals.go
  3. 8
      cmd/test-utils_test.go

@ -39,7 +39,7 @@ var GlobalServiceDoneCh chan struct{}
// Initialize service mutex once. // Initialize service mutex once.
func init() { func init() {
GlobalServiceDoneCh = make(chan struct{}, 1) GlobalServiceDoneCh = make(chan struct{})
globalServiceSignalCh = make(chan serviceSignal) globalServiceSignalCh = make(chan serviceSignal)
} }

@ -52,6 +52,9 @@ func handleSignals() {
err = globalHTTPServer.Shutdown() err = globalHTTPServer.Shutdown()
logger.LogIf(context.Background(), err) logger.LogIf(context.Background(), err)
// send signal to various go-routines that they need to quit.
close(GlobalServiceDoneCh)
if objAPI := newObjectLayerFn(); objAPI != nil { if objAPI := newObjectLayerFn(); objAPI != nil {
oerr = objAPI.Shutdown(context.Background()) oerr = objAPI.Shutdown(context.Background())
logger.LogIf(context.Background(), oerr) logger.LogIf(context.Background(), oerr)

@ -407,6 +407,11 @@ func resetGlobalConfigPath() {
globalConfigDir = &ConfigDir{path: ""} globalConfigDir = &ConfigDir{path: ""}
} }
func resetGlobalServiceDoneCh() {
close(GlobalServiceDoneCh)
GlobalServiceDoneCh = make(chan struct{})
}
// sets globalObjectAPI to `nil`. // sets globalObjectAPI to `nil`.
func resetGlobalObjectAPI() { func resetGlobalObjectAPI() {
globalObjLayerMutex.Lock() globalObjLayerMutex.Lock()
@ -479,6 +484,9 @@ func resetGlobalIAMSys() {
// Resets all the globals used modified in tests. // Resets all the globals used modified in tests.
// Resetting ensures that the changes made to globals by one test doesn't affect others. // Resetting ensures that the changes made to globals by one test doesn't affect others.
func resetTestGlobals() { func resetTestGlobals() {
// close any indefinitely running go-routines from previous
// tests.
resetGlobalServiceDoneCh()
// set globalObjectAPI to `nil`. // set globalObjectAPI to `nil`.
resetGlobalObjectAPI() resetGlobalObjectAPI()
// Reset config path set. // Reset config path set.

Loading…
Cancel
Save