Skip to content

Commit e0e66a9

Browse files
stariushieblmi
authored andcommitted
loopd: fix data races of logger
1 parent 2249c41 commit e0e66a9

File tree

8 files changed

+116
-81
lines changed

8 files changed

+116
-81
lines changed

loopd/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func getTLSConfig(cfg *Config) (*tls.Config, *credentials.TransportCredentials,
423423
// If the certificate expired or it was outdated, delete it and the TLS
424424
// key and generate a new pair.
425425
if time.Now().After(parsedCert.NotAfter) {
426-
log.Info("TLS certificate is expired or outdated, " +
426+
infof("TLS certificate is expired or outdated, " +
427427
"removing old file then generating a new one")
428428

429429
err := os.Remove(cfg.TLSCertPath)
@@ -464,7 +464,7 @@ func loadCertWithCreate(cfg *Config) (tls.Certificate, *x509.Certificate,
464464
if !lnrpc.FileExists(cfg.TLSCertPath) &&
465465
!lnrpc.FileExists(cfg.TLSKeyPath) {
466466

467-
log.Infof("Generating TLS certificates...")
467+
infof("Generating TLS certificates...")
468468
certBytes, keyBytes, err := cert.GenCertPair(
469469
defaultSelfSignedOrganization, cfg.TLSExtraIPs,
470470
cfg.TLSExtraDomains, cfg.TLSDisableAutofill,
@@ -481,7 +481,7 @@ func loadCertWithCreate(cfg *Config) (tls.Certificate, *x509.Certificate,
481481
return tls.Certificate{}, nil, err
482482
}
483483

484-
log.Infof("Done generating TLS certificates")
484+
infof("Done generating TLS certificates")
485485
}
486486

487487
return cert.LoadCert(cfg.TLSCertPath, cfg.TLSKeyPath)

loopd/daemon.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ func (d *Daemon) Start() error {
169169
// anything goes wrong now, we need to cleanly shut down again.
170170
startErr := d.startWebServers()
171171
if startErr != nil {
172-
log.Errorf("Error while starting daemon: %v", err)
172+
errorf("Error while starting daemon: %v", err)
173173
d.Stop()
174174
stopErr := <-d.ErrChan
175175
if stopErr != nil {
176-
log.Errorf("Error while stopping daemon: %v", stopErr)
176+
errorf("Error while stopping daemon: %v", stopErr)
177177
}
178178
return startErr
179179
}
@@ -253,7 +253,7 @@ func (d *Daemon) startWebServers() error {
253253
d.registerDebugServer()
254254

255255
// Next, start the gRPC server listening for HTTP/2 connections.
256-
log.Infof("Starting gRPC listener")
256+
infof("Starting gRPC listener")
257257
serverTLSCfg, restClientCreds, err := getTLSConfig(d.cfg)
258258
if err != nil {
259259
return fmt.Errorf("could not create gRPC server options: %v",
@@ -322,7 +322,7 @@ func (d *Daemon) startWebServers() error {
322322

323323
// A nil listener indicates REST is disabled.
324324
if d.restListener != nil {
325-
log.Infof("Starting REST proxy listener")
325+
infof("Starting REST proxy listener")
326326

327327
d.restServer = &http.Server{
328328
Handler: restHandler,
@@ -333,7 +333,7 @@ func (d *Daemon) startWebServers() error {
333333
go func() {
334334
defer d.wg.Done()
335335

336-
log.Infof("REST proxy listening on %s",
336+
infof("REST proxy listening on %s",
337337
d.restListener.Addr())
338338
err := d.restServer.Serve(d.restListener)
339339
// ErrServerClosed is always returned when the proxy is
@@ -347,15 +347,15 @@ func (d *Daemon) startWebServers() error {
347347
}
348348
}()
349349
} else {
350-
log.Infof("REST proxy disabled")
350+
infof("REST proxy disabled")
351351
}
352352

353353
// Start the grpc server.
354354
d.wg.Add(1)
355355
go func() {
356356
defer d.wg.Done()
357357

358-
log.Infof("RPC server listening on %s", d.grpcListener.Addr())
358+
infof("RPC server listening on %s", d.grpcListener.Addr())
359359
err = d.grpcServer.Serve(d.grpcListener)
360360
if err != nil && !errors.Is(err, grpc.ErrServerStopped) {
361361
// Notify the main error handler goroutine that
@@ -378,7 +378,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
378378
loopdb.EnableExperimentalProtocol()
379379
}
380380

381-
log.Infof("Protocol version: %v", loopdb.CurrentProtocolVersion())
381+
infof("Protocol version: %v", loopdb.CurrentProtocolVersion())
382382

383383
// If no swap server is specified, use the default addresses for mainnet
384384
// and testnet.
@@ -404,18 +404,18 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
404404
// on main context cancel. So we create it early and pass it down.
405405
d.mainCtx, d.mainCtxCancel = context.WithCancel(context.Background())
406406

407-
log.Infof("Swap server address: %v", d.cfg.Server.Host)
407+
infof("Swap server address: %v", d.cfg.Server.Host)
408408

409409
// Check if we need to migrate the database.
410410
if needSqlMigration(d.cfg) {
411-
log.Infof("Boltdb found, running migration")
411+
infof("Boltdb found, running migration")
412412

413413
err := migrateBoltdb(d.mainCtx, d.cfg)
414414
if err != nil {
415415
return fmt.Errorf("unable to migrate boltdb: %v", err)
416416
}
417417

418-
log.Infof("Successfully migrated boltdb")
418+
infof("Successfully migrated boltdb")
419419
}
420420

421421
// Now that we know where the database will live, we'll go ahead and
@@ -436,7 +436,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
436436
swapDb,
437437
)
438438
if err != nil {
439-
log.Errorf("Cost migration failed: %v", err)
439+
errorf("Cost migration failed: %v", err)
440440

441441
return err
442442
}
@@ -460,7 +460,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
460460
d.lnd.NodePubkey)
461461
}
462462

463-
log.Infof("Using asset client with version %v", getInfo.Version)
463+
infof("Using asset client with version %v", getInfo.Version)
464464
}
465465

466466
// Create an instance of the loop client library.
@@ -507,7 +507,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
507507
cleanupMacaroonStore := func() {
508508
err := db.Close()
509509
if err != nil {
510-
log.Errorf("Error closing macaroon store: %v", err)
510+
errorf("Error closing macaroon store: %v", err)
511511
}
512512
}
513513

@@ -555,11 +555,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
555555
go func() {
556556
defer d.wg.Done()
557557

558-
log.Info("Starting notification manager")
558+
infof("Starting notification manager")
559559
err := notificationManager.Run(d.mainCtx)
560560
if err != nil {
561561
d.internalErrChan <- err
562-
log.Errorf("Notification manager stopped: %v", err)
562+
errorf("Notification manager stopped: %v", err)
563563
}
564564
}()
565565

@@ -711,7 +711,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
711711
// started yet, so if we clean that up now, nothing else needs
712712
// to be shut down at this point.
713713
if err := d.macaroonService.Stop(); err != nil {
714-
log.Errorf("Error shutting down macaroon service: %v",
714+
errorf("Error shutting down macaroon service: %v",
715715
err)
716716
}
717717
cleanupMacaroonStore()
@@ -728,7 +728,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
728728
go func() {
729729
defer d.wg.Done()
730730

731-
log.Infof("Starting swap client")
731+
infof("Starting swap client")
732732
err := d.impl.Run(d.mainCtx, d.statusChan)
733733
if err != nil {
734734
// Notify the main error handler goroutine that
@@ -737,29 +737,29 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
737737
// channel is sufficiently buffered.
738738
d.internalErrChan <- err
739739
}
740-
log.Infof("Swap client stopped")
740+
infof("Swap client stopped")
741741
}()
742742

743743
// Start a goroutine that broadcasts swap updates to clients.
744744
d.wg.Add(1)
745745
go func() {
746746
defer d.wg.Done()
747747

748-
log.Infof("Waiting for updates")
748+
infof("Waiting for updates")
749749
d.processStatusUpdates(d.mainCtx)
750750
}()
751751

752752
d.wg.Add(1)
753753
go func() {
754754
defer d.wg.Done()
755755

756-
log.Info("Starting liquidity manager")
756+
infof("Starting liquidity manager")
757757
err := d.liquidityMgr.Run(d.mainCtx)
758758
if err != nil && !errors.Is(err, context.Canceled) {
759759
d.internalErrChan <- err
760760
}
761761

762-
log.Info("Liquidity manager stopped")
762+
infof("Liquidity manager stopped")
763763
}()
764764

765765
// Start the reservation manager.
@@ -777,8 +777,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
777777
return
778778
}
779779

780-
log.Info("Starting reservation manager")
781-
defer log.Info("Reservation manager stopped")
780+
infof("Starting reservation manager")
781+
defer infof("Reservation manager stopped")
782782

783783
err = d.reservationManager.Run(
784784
d.mainCtx, int32(getInfo.BlockHeight), initChan,
@@ -815,8 +815,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
815815
return
816816
}
817817

818-
log.Info("Starting instantout manager")
819-
defer log.Info("Instantout manager stopped")
818+
infof("Starting instantout manager")
819+
defer infof("Instantout manager stopped")
820820

821821
err = d.instantOutManager.Run(
822822
d.mainCtx, initChan, int32(getInfo.BlockHeight),
@@ -846,12 +846,12 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
846846
go func() {
847847
defer d.wg.Done()
848848

849-
log.Info("Starting static address manager...")
849+
infof("Starting static address manager...")
850850
err = staticAddressManager.Run(d.mainCtx)
851851
if err != nil && !errors.Is(context.Canceled, err) {
852852
d.internalErrChan <- err
853853
}
854-
log.Info("Static address manager stopped")
854+
infof("Static address manager stopped")
855855
}()
856856
}
857857

@@ -869,12 +869,12 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
869869
return
870870
}
871871

872-
log.Info("Starting static address deposit manager...")
872+
infof("Starting static address deposit manager...")
873873
err = depositManager.Run(d.mainCtx, info.BlockHeight)
874874
if err != nil && !errors.Is(context.Canceled, err) {
875875
d.internalErrChan <- err
876876
}
877-
log.Info("Static address deposit manager stopped")
877+
infof("Static address deposit manager stopped")
878878
}()
879879
depositManager.WaitInitComplete()
880880
}
@@ -893,13 +893,13 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
893893
return
894894
}
895895

896-
log.Info("Starting static address deposit withdrawal " +
896+
infof("Starting static address deposit withdrawal " +
897897
"manager...")
898898
err = withdrawalManager.Run(d.mainCtx, info.BlockHeight)
899899
if err != nil && !errors.Is(context.Canceled, err) {
900900
d.internalErrChan <- err
901901
}
902-
log.Info("Static address deposit withdrawal manager " +
902+
infof("Static address deposit withdrawal manager " +
903903
"stopped")
904904
}()
905905
withdrawalManager.WaitInitComplete()
@@ -920,14 +920,14 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
920920
return
921921
}
922922

923-
log.Info("Starting static address loop-in manager...")
923+
infof("Starting static address loop-in manager...")
924924
err = staticLoopInManager.Run(
925925
d.mainCtx, info.BlockHeight,
926926
)
927927
if err != nil && !errors.Is(context.Canceled, err) {
928928
d.internalErrChan <- err
929929
}
930-
log.Info("Starting static address loop-in manager " +
930+
infof("Starting static address loop-in manager " +
931931
"stopped")
932932
}()
933933
staticLoopInManager.WaitInitComplete()
@@ -948,7 +948,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
948948
// signal the caller that we're done.
949949
select {
950950
case runtimeErr = <-d.internalErrChan:
951-
log.Errorf("Runtime error in daemon, shutting down: "+
951+
errorf("Runtime error in daemon, shutting down: "+
952952
"%v", runtimeErr)
953953

954954
case <-d.quit:
@@ -958,7 +958,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
958958
// otherwise a caller might exit the process too early.
959959
d.stop()
960960
cleanupMacaroonStore()
961-
log.Info("Daemon exited")
961+
infof("Daemon exited")
962962

963963
// The caller expects exactly one message. So we send the error
964964
// even if it's nil because we cleanly shut down.
@@ -987,17 +987,17 @@ func (d *Daemon) stop() {
987987

988988
// As there is no swap activity anymore, we can forcefully shut down the
989989
// gRPC and HTTP servers now.
990-
log.Infof("Stopping gRPC server")
990+
infof("Stopping gRPC server")
991991
if d.grpcServer != nil {
992992
d.grpcServer.Stop()
993993
}
994-
log.Infof("Stopping REST server")
994+
infof("Stopping REST server")
995995
if d.restServer != nil {
996996
// Don't return the error here, we first want to give everything
997997
// else a chance to shut down cleanly.
998998
err := d.restServer.Close()
999999
if err != nil {
1000-
log.Errorf("Error stopping REST server: %v", err)
1000+
errorf("Error stopping REST server: %v", err)
10011001
}
10021002
}
10031003
if d.restCtxCancel != nil {
@@ -1007,7 +1007,7 @@ func (d *Daemon) stop() {
10071007
if d.macaroonService != nil {
10081008
err := d.macaroonService.Stop()
10091009
if err != nil {
1010-
log.Errorf("Error stopping macaroon service: %v", err)
1010+
errorf("Error stopping macaroon service: %v", err)
10111011
}
10121012
}
10131013

0 commit comments

Comments
 (0)