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

fix: plugin grpc server retry method #1096

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 23 additions & 9 deletions internal/plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ func (plugin *nvidiaDevicePlugin) Serve() error {
go func() {
lastCrashTime := time.Now()
restartCount := 0
// quite if it has been restarted too often
// i.e. if server has crashed more than 5 times and it didn't last more than one hour each time
maxRestarts := 5
crashTimeout := 1 * time.Hour

for {
// quite if it has been restarted too often
// i.e. if server has crashed more than 5 times and it didn't last more than one hour each time
if restartCount > 5 {
if restartCount > maxRestarts {
// quit
klog.Fatalf("GRPC server for '%s' has repeatedly crashed recently. Quitting", plugin.rm.Resource())
}
Expand All @@ -198,17 +200,29 @@ func (plugin *nvidiaDevicePlugin) Serve() error {
break
}

klog.Infof("GRPC server for '%s' crashed with error: %v", plugin.rm.Resource(), err)

timeSinceLastCrash := time.Since(lastCrashTime).Seconds()
timeSinceLastCrash := time.Since(lastCrashTime)
lastCrashTime = time.Now()
if timeSinceLastCrash > 3600 {
// it has been one hour since the last crash.. reset the count
// to reflect on the frequency

klog.Errorf(
"GRPC server for '%s' crashed with error: %v. Retry attempt: %d, Time since last crash: %.2f seconds",
plugin.rm.Resource(),
err,
restartCount+1,
timeSinceLastCrash.Seconds(),
)

if timeSinceLastCrash > crashTimeout {
// time since last crash exceeds crashTimeout, reset the restartCount
klog.Infof("Time since last crash exceeds crashTimeout (%v), resetting restart count", crashTimeout)
restartCount = 0
} else {
restartCount++
}

// add a small delay before restarting to prevent tight loops
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that you chose 5 seconds specifically? This seems quite long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, 5 seconds is too long, I changed it to 500 Millisecond. wdyt 🤔

retryDelay := time.Millisecond * 500
klog.Infof("Waiting for %v before attempting to restart GRPC server for '%s'", retryDelay.String(), plugin.rm.Resource())
time.Sleep(time.Millisecond * 500)
}
}()

Expand Down