@@ -774,6 +774,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
774774 infof ("Liquidity manager stopped" )
775775 }()
776776
777+ initManagerTimeout := 10 * time .Second
778+
777779 // Start the reservation manager.
778780 if d .reservationManager != nil {
779781 d .wg .Add (1 )
@@ -792,9 +794,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
792794 }
793795 }()
794796
795- // Wait for the reservation server to be ready before starting the
796- // grpc server.
797- timeOutCtx , cancel := context .WithTimeout (d .mainCtx , 10 * time .Second )
797+ // Wait for the reservation server to be ready before starting
798+ // the grpc server.
799+ timeOutCtx , cancel := context .WithTimeout (
800+ d .mainCtx , initManagerTimeout ,
801+ )
798802 select {
799803 case <- timeOutCtx .Done ():
800804 cancel ()
@@ -822,9 +826,11 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
822826 }
823827 }()
824828
825- // Wait for the instantout server to be ready before starting the
826- // grpc server.
827- timeOutCtx , cancel := context .WithTimeout (d .mainCtx , 10 * time .Second )
829+ // Wait for the instantout server to be ready before starting
830+ // the grpc server.
831+ timeOutCtx , cancel := context .WithTimeout (
832+ d .mainCtx , initManagerTimeout ,
833+ )
828834 select {
829835 case <- timeOutCtx .Done ():
830836 cancel ()
@@ -839,67 +845,128 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
839845 // Start the static address manager.
840846 if staticAddressManager != nil {
841847 d .wg .Add (1 )
848+ initChan := make (chan struct {})
842849 go func () {
843850 defer d .wg .Done ()
844851
845852 infof ("Starting static address manager..." )
846- err := staticAddressManager .Run (d .mainCtx )
853+ defer infof ("Static address manager stopped" )
854+
855+ err := staticAddressManager .Run (d .mainCtx , initChan )
847856 if err != nil && ! errors .Is (context .Canceled , err ) {
848857 d .internalErrChan <- err
849858 }
850- infof ("Static address manager stopped" )
851859 }()
860+
861+ // Wait for the static address manager to be ready before
862+ // starting the grpc server.
863+ timeOutCtx , cancel := context .WithTimeout (
864+ d .mainCtx , initManagerTimeout ,
865+ )
866+ select {
867+ case <- timeOutCtx .Done ():
868+ cancel ()
869+ return fmt .Errorf ("static address manager not " +
870+ "ready: %v" , timeOutCtx .Err ())
871+
872+ case <- initChan :
873+ cancel ()
874+ }
852875 }
853876
854877 // Start the static address deposit manager.
855878 if depositManager != nil {
856879 d .wg .Add (1 )
880+ initChan := make (chan struct {})
857881 go func () {
858882 defer d .wg .Done ()
859883
860884 infof ("Starting static address deposit manager..." )
861- err := depositManager .Run (d .mainCtx )
885+ defer infof ("Static address deposit manager stopped" )
886+
887+ err := depositManager .Run (d .mainCtx , initChan )
862888 if err != nil && ! errors .Is (context .Canceled , err ) {
863889 d .internalErrChan <- err
864890 }
865- infof ("Static address deposit manager stopped" )
866891 }()
867- depositManager .WaitInitComplete ()
892+
893+ // Wait for the static address manager to be ready before
894+ // starting the grpc server.
895+ timeOutCtx , cancel := context .WithTimeout (
896+ d .mainCtx , initManagerTimeout ,
897+ )
898+ select {
899+ case <- timeOutCtx .Done ():
900+ cancel ()
901+ return fmt .Errorf ("static address deposit manager " +
902+ "not ready: %v" , timeOutCtx .Err ())
903+
904+ case <- initChan :
905+ cancel ()
906+ }
868907 }
869908
870909 // Start the static address deposit withdrawal manager.
871910 if withdrawalManager != nil {
872911 d .wg .Add (1 )
912+ initChan := make (chan struct {})
873913 go func () {
874914 defer d .wg .Done ()
875915
876- infof ("Starting static address deposit withdrawal " +
877- "manager..." )
878- err := withdrawalManager .Run (d .mainCtx )
916+ infof ("Starting static address withdrawal manager..." )
917+ defer infof ("Static address withdrawal manager stopped" )
918+
919+ err := withdrawalManager .Run (d .mainCtx , initChan )
879920 if err != nil && ! errors .Is (context .Canceled , err ) {
880921 d .internalErrChan <- err
881922 }
882- infof ("Static address deposit withdrawal manager " +
883- "stopped" )
884923 }()
885- withdrawalManager .WaitInitComplete ()
924+
925+ // Wait for the static address withdrawal manager to be ready
926+ // before starting the grpc server.
927+ timeOutCtx , cancel := context .WithTimeout (
928+ d .mainCtx , initManagerTimeout ,
929+ )
930+ select {
931+ case <- timeOutCtx .Done ():
932+ cancel ()
933+ return fmt .Errorf ("static address withdrawal manager " +
934+ "server not ready: %v" , timeOutCtx .Err ())
935+
936+ case <- initChan :
937+ cancel ()
938+ }
886939 }
887940
888941 // Start the static address loop-in manager.
889942 if staticLoopInManager != nil {
890943 d .wg .Add (1 )
944+ initChan := make (chan struct {})
891945 go func () {
892946 defer d .wg .Done ()
893947
894948 infof ("Starting static address loop-in manager..." )
895- err := staticLoopInManager .Run (d .mainCtx )
949+ defer infof ("Static address loop-in manager stopped" )
950+ err := staticLoopInManager .Run (d .mainCtx , initChan )
896951 if err != nil && ! errors .Is (context .Canceled , err ) {
897952 d .internalErrChan <- err
898953 }
899- infof ("Starting static address loop-in manager " +
900- "stopped" )
901954 }()
902- staticLoopInManager .WaitInitComplete ()
955+
956+ // Wait for the static address loop-in manager to be ready before
957+ // starting the grpc server.
958+ timeOutCtx , cancel := context .WithTimeout (
959+ d .mainCtx , initManagerTimeout ,
960+ )
961+ select {
962+ case <- timeOutCtx .Done ():
963+ cancel ()
964+ return fmt .Errorf ("static address loop-in manager " +
965+ "not ready: %v" , timeOutCtx .Err ())
966+
967+ case <- initChan :
968+ cancel ()
969+ }
903970 }
904971
905972 // Last, start our internal error handler. This will return exactly one
0 commit comments