freeze before exit when _MINIO_DEBUG_NO_EXIT is defined (#15709)

this is to ensure keep k8s pods running, when they reach a "crashloop" stage
This commit is contained in:
Anis Elleuch
2022-09-22 19:57:27 +01:00
committed by GitHub
parent 6f56ba80b3
commit 20c89ebbb3
2 changed files with 27 additions and 3 deletions

View File

@@ -23,11 +23,13 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strings"
"github.com/minio/cli"
"github.com/minio/minio/internal/color"
"github.com/minio/minio/internal/logger"
"github.com/minio/pkg/console"
"github.com/minio/pkg/trie"
"github.com/minio/pkg/words"
@@ -189,8 +191,27 @@ func Main(args []string) {
// Set the minio app name.
appName := filepath.Base(args[0])
if os.Getenv("_MINIO_DEBUG_NO_EXIT") != "" {
freeze := func(_ int) {
// Infinite blocking op
<-make(chan struct{})
}
// Override the logger os.Exit()
logger.ExitFunc = freeze
defer func() {
if err := recover(); err != nil {
fmt.Println("panic:", err)
fmt.Println("")
fmt.Println(string(debug.Stack()))
}
freeze(-1)
}()
}
// Run the app - exit on error.
if err := newApp(appName).Run(args); err != nil {
os.Exit(1)
os.Exit(1) //nolint:gocritic
}
}