diff --git a/cmd/service.go b/cmd/service.go index 36212f5f6..fb37052a5 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -39,7 +39,7 @@ var GlobalServiceDoneCh chan struct{} // Initialize service mutex once. func init() { - GlobalServiceDoneCh = make(chan struct{}, 1) + GlobalServiceDoneCh = make(chan struct{}) globalServiceSignalCh = make(chan serviceSignal) } diff --git a/cmd/signals.go b/cmd/signals.go index a3f8eab4d..9660eb6ab 100644 --- a/cmd/signals.go +++ b/cmd/signals.go @@ -52,6 +52,9 @@ func handleSignals() { err = globalHTTPServer.Shutdown() logger.LogIf(context.Background(), err) + // send signal to various go-routines that they need to quit. + close(GlobalServiceDoneCh) + if objAPI := newObjectLayerFn(); objAPI != nil { oerr = objAPI.Shutdown(context.Background()) logger.LogIf(context.Background(), oerr) diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 89b36fc55..e8f688c38 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -407,6 +407,11 @@ func resetGlobalConfigPath() { globalConfigDir = &ConfigDir{path: ""} } +func resetGlobalServiceDoneCh() { + close(GlobalServiceDoneCh) + GlobalServiceDoneCh = make(chan struct{}) +} + // sets globalObjectAPI to `nil`. func resetGlobalObjectAPI() { globalObjLayerMutex.Lock() @@ -479,6 +484,9 @@ func resetGlobalIAMSys() { // Resets all the globals used modified in tests. // Resetting ensures that the changes made to globals by one test doesn't affect others. func resetTestGlobals() { + // close any indefinitely running go-routines from previous + // tests. + resetGlobalServiceDoneCh() // set globalObjectAPI to `nil`. resetGlobalObjectAPI() // Reset config path set.