Skip to content

Commit

Permalink
services: fix logs flush after services shutdown
Browse files Browse the repository at this point in the history
Added sync logs for every service separately to provide the ability to
have a custom logger for each service. Data race in logging is fixed by
adding a sync log, this problem is related to uber-go/zap#687.

 Close #2973
 Close #2974
 Close #3112
 Close #3217

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Feb 14, 2024
1 parent 7a1b707 commit 92174fb
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func (s *service) Shutdown() {
s.wallet.Close()
}
}
_ = s.log.Sync()
}

func (s *service) eventLoop() {
Expand Down
1 change: 1 addition & 0 deletions pkg/core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,7 @@ func (bc *Blockchain) Close() {
close(bc.stopCh)
<-bc.runToExitCh
bc.addLock.Unlock()
_ = bc.log.Sync()
}

// AddBlock accepts successive block for the Blockchain, verifies it and
Expand Down
2 changes: 2 additions & 0 deletions pkg/network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ func (s *Server) Shutdown() {
}
close(s.quit)
<-s.relayFin

_ = s.log.Sync()
}

// AddService allows to add a service to be started/stopped by Server.
Expand Down
1 change: 1 addition & 0 deletions pkg/services/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ func (ms *Service) ShutDown() {
ms.log.Error("can't shut service down", zap.String("endpoint", srv.Addr), zap.Error(err))
}
}
_ = ms.log.Sync()
}
1 change: 1 addition & 0 deletions pkg/services/notary/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func (n *Notary) Shutdown() {
close(n.stopCh)
<-n.done
n.wallet.Close()
_ = n.Config.Log.Sync()
}

// IsAuthorized returns whether Notary service currently is authorized to collect
Expand Down
1 change: 1 addition & 0 deletions pkg/services/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (o *Oracle) Shutdown() {
o.ResponseHandler.Shutdown()
<-o.done
o.wallet.Close()
_ = o.Log.Sync()
}

// Start runs the oracle service in a separate goroutine.
Expand Down
1 change: 1 addition & 0 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func (s *Server) Shutdown() {

// Wait for handleSubEvents to finish.
<-s.subEventsToExitCh
_ = s.log.Sync()
}

// SetOracleHandler allows to update oracle handler used by the Server.
Expand Down
1 change: 1 addition & 0 deletions pkg/services/stateroot/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *service) Shutdown() {
if s.wallet != nil {
s.wallet.Close()
}
_ = s.log.Sync()
}

func (s *service) signAndSend(r *state.MPTRoot) error {
Expand Down

0 comments on commit 92174fb

Please sign in to comment.