Merge pull request #2126 from nspcc-dev/prevent-inconsistent-exit-2.x

core: take an addblock lock on exit
This commit is contained in:
Roman Khimov 2021-08-12 17:47:11 +03:00 committed by GitHub
commit f38d62ab14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -300,6 +300,7 @@ func (bc *Blockchain) Run() {
persistTimer := time.NewTimer(persistInterval)
defer func() {
persistTimer.Stop()
bc.addLock.Lock() // Prevent changing state, but do not release the lock, we're about to exit.
if err := bc.persist(); err != nil {
bc.log.Warn("failed to persist", zap.Error(err))
}