Skip to content

Commit

Permalink
server: wait for comet node shutdown (#444)
Browse files Browse the repository at this point in the history
* server: wait for comet node shutdown

cometbft's service Start() methods do not block while running,
so we the errgroup.Go for this was returning almost right away.
This meant that errgroup.Wait() did not wait for shutdown to
complete. The effect was frequent errors from cometbft arising
from one of our databases / key stores being shutdown too soon.

This is now resolved and the dependencies `closers` aren't closed
until the node is actually stopped.

However, there is still an internal cometbft bug during block sync
(before the nodes switches to consensus mode) because of an
unsupervised goroutine, `blocksync.(*Reactor).poolRoutine`. I fixed
this bug in blocksync/reactor.go and the errors go away. We may
need to PR cometbft to get clean shutdown during block sync.

* deps: update cometbft to v0.38.x HEAD
  • Loading branch information
jchappelow authored and brennanjl committed Feb 26, 2024
1 parent 8f4469c commit e933102
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 530 deletions.
21 changes: 12 additions & 9 deletions cmd/kwild/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,20 @@ func (s *Server) Start(ctx context.Context) error {
s.log.Info("grpc server started", zap.String("address", s.cfg.AppCfg.AdminListenAddress))

group.Go(func() error {
go func() {
<-groupCtx.Done()
s.log.Info("stop comet server")
if err := s.cometBftNode.Stop(); err != nil {
s.log.Warn("failed to stop comet server", zap.Error(err))
}
}()
// The CometBFT services do not block on Start().
if err := s.cometBftNode.Start(); err != nil {
return err
}
s.log.Info("comet node is now started")

return s.cometBftNode.Start()
<-groupCtx.Done()
s.log.Info("stop comet server")
if err := s.cometBftNode.Stop(); err != nil {
return fmt.Errorf("failed to stop comet server: %w", err)
}
s.log.Info("comet server is stopped")
return nil
})
s.log.Info("comet node started")

err := group.Wait()

Expand Down
50 changes: 26 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace (
require (
dario.cat/mergo v1.0.0
github.com/alexliesenfeld/health v0.6.0
github.com/cometbft/cometbft v0.38.2
github.com/cometbft/cometbft v0.38.3-0.20240108012115-1e434f11faa2
github.com/cosmos/gogoproto v1.4.11
github.com/dgraph-io/badger/v3 v3.2103.5
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.5
Expand All @@ -24,16 +24,16 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/near/borsh-go v0.3.1
github.com/olekukonko/tablewriter v0.0.5
github.com/pelletier/go-toml/v2 v2.0.6
github.com/spf13/cobra v1.7.0
github.com/pelletier/go-toml/v2 v2.1.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/spf13/viper v1.18.1
github.com/stretchr/testify v1.8.4
github.com/tonistiigi/go-rosetta v0.0.0-20220804170347-3f4430f2d346
go.uber.org/zap v1.26.0
golang.org/x/sync v0.3.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97
google.golang.org/grpc v1.58.3
golang.org/x/sync v0.5.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f
google.golang.org/grpc v1.60.0
google.golang.org/protobuf v1.31.0
)

Expand All @@ -50,10 +50,10 @@ require (
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/containerd/continuity v0.4.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/cstockton/go-conv v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/certgen v1.1.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
Expand All @@ -62,27 +62,27 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/ethereum/go-ethereum v1.13.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kwilteam/action-grammar-go v0.0.1-0.20230926160920-472768e1186c // indirect
github.com/kwilteam/sql-grammar-go v0.0.3-0.20230925230724-00685e1bac32 // indirect
github.com/lib/pq v1.10.7 // indirect
Expand All @@ -99,7 +99,7 @@ require (
github.com/opencontainers/runc v1.1.7 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
Expand All @@ -109,27 +109,29 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231009173412-8bfb1ae86b6c // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.3 // indirect
Expand Down
Loading

0 comments on commit e933102

Please sign in to comment.