[NOD-1239] Delete app.WaitForShutdown() (#866)

This commit is contained in:
Ori Newman 2020-08-12 16:38:52 +03:00 committed by GitHub
parent 22dc3f998f
commit ca3172dad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 21 deletions

View File

@ -62,11 +62,11 @@ func (a *App) Start() {
}
// Stop gracefully shuts down all the kaspad services.
func (a *App) Stop() error {
func (a *App) Stop() {
// Make sure this only happens once.
if atomic.AddInt32(&a.shutdown, 1) != 1 {
log.Infof("Kaspad is already in the process of shutting down")
return nil
return
}
log.Warnf("Kaspad shutting down")
@ -86,7 +86,12 @@ func (a *App) Stop() error {
}
}
return nil
err = a.addressManager.Stop()
if err != nil {
log.Errorf("Error stopping address manager: %s", err)
}
return
}
// New returns a new App instance configured to listen on addr for the
@ -241,9 +246,3 @@ func (a *App) P2PNodeID() *id.ID {
func (a *App) AddressManager() *addressmanager.AddressManager {
return a.addressManager
}
// WaitForShutdown blocks until the main listener and peer handlers are stopped.
func (a *App) WaitForShutdown() {
// TODO(libp2p)
// a.p2pServer.WaitForShutdown()
}

View File

@ -97,14 +97,9 @@ func setRPCClient(t *testing.T, harness *appHarness) {
}
func teardownHarness(t *testing.T, harness *appHarness) {
err := harness.app.Stop()
if err != nil {
t.Errorf("Error stopping App: %+v", err)
}
harness.app.Stop()
harness.app.WaitForShutdown()
err = harness.databaseContext.Close()
err := harness.databaseContext.Close()
if err != nil {
t.Errorf("Error closing database context: %+v", err)
}

View File

@ -132,14 +132,10 @@ func kaspadMain(startedChan chan<- struct{}) error {
}
defer func() {
log.Infof("Gracefully shutting down kaspad...")
err := app.Stop()
if err != nil {
log.Errorf("Error stopping kaspad: %+v", err)
}
shutdownDone := make(chan struct{})
go func() {
app.WaitForShutdown()
app.Stop()
shutdownDone <- struct{}{}
}()