-
Notifications
You must be signed in to change notification settings - Fork 20k
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
cmd/utils: Handle graceful shutdown on low disk space #21884
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ func StartNode(stack *node.Node) { | |
sigc := make(chan os.Signal, 1) | ||
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) | ||
defer signal.Stop(sigc) | ||
go ensureSufficientMemory(sigc) | ||
<-sigc | ||
log.Info("Got interrupt, shutting down...") | ||
go stack.Close() | ||
|
@@ -312,3 +313,28 @@ func ExportPreimages(db ethdb.Database, fn string) error { | |
log.Info("Exported preimages", "file", fn) | ||
return nil | ||
} | ||
|
||
func ensureSufficientMemory(sigc chan os.Signal) { | ||
for t := range time.Tick(5 * time.Second) { | ||
select { | ||
case <-sigc: | ||
log.Info("Node is being terminated...") | ||
default: | ||
go func() { | ||
var stat syscall.Statfs_t | ||
wd, err := os.Getwd(); err != nil { | ||
Fatalf("Error reading available memory of Node: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in c355ae4 |
||
} | ||
syscall.Statfs(wd, &stat) | ||
MB = 1000000 | ||
avMemMB = stat.Bavail * uint64(stat.Bsize) / MB | ||
if avMemMB < 100 { | ||
log.Info("Available disk space is less than 100 MB. Gracefully shutting down to prevent database corruption.") | ||
sigc <- syscall.SIGTERM | ||
} else if avMemMB < 500 { | ||
log.Warnf("Node is running low on memory. It will terminate if memory runs below 100MB. Remaining: %v MB.", avMemMB) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in c355ae4 |
||
} | ||
}() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit confusing to have this method named
ensureSufficientMemory
, as it's disk-space, not RAM that's being checked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c355ae4