-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
Fixes #20859 added unsafe shutdown detector #21133
Changes from all commits
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"runtime" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
|
@@ -231,6 +232,15 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { | |
return nil, err | ||
} | ||
|
||
// Check for invalid shutdown | ||
invalidShutdown, _ := chainDb.Get([]byte("unsafe-shutdown")) | ||
if invalidShutdown != nil { | ||
log.Error("unsafe shutdown detected", "time", string(invalidShutdown)) | ||
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 capitalize the log message. Also please use a proper time value, not a pre-stringified version. |
||
} | ||
// Create an invalid shutdown in database in case the app crashed | ||
if err = chainDb.Put([]byte("unsafe-shutdown"), []byte(time.Now().String())); err != nil { | ||
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. Pls use time.Now().Unix() to store the current timestamp instead of a localized string |
||
log.Warn("Failed to record possible future unsafe shutdown", "err", 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. I think it's safe to |
||
} | ||
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. The PR uses a single A simplistic suggestion would be to use a slice of timestamps instead of a single timestamp as the value of the entry. When Geth starts, you can append the current time, and on shutdown, you can pop off the tail. That way on startup you can actually list all the recent crashes, not just the last one. |
||
return eth, nil | ||
} | ||
|
||
|
@@ -567,6 +577,9 @@ func (s *Ethereum) Stop() error { | |
s.lesServer.Stop() | ||
} | ||
|
||
if err := s.chainDb.Delete([]byte("unsafe-shutdown")); err != nil { | ||
log.Error("err", 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. You'll need to move this down, right above |
||
// Then stop everything else. | ||
s.bloomIndexer.Close() | ||
close(s.closeBloomHandler) | ||
|
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.
Since you're using
unsafe-shutdown
in quite a few places and in different packages, it might make sense to move this intocore/rawdb/schema.go
. We have a lot of other metadata keys defined there.