diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index ec8155b01f..bc0e8e7f7f 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1767,6 +1767,7 @@ out: func (s *Switch) Start() error { if !atomic.CompareAndSwapInt32(&s.started, 0, 1) { log.Warn("Htlc Switch already started") + return errors.New("htlc switch already started") } @@ -1782,15 +1783,19 @@ func (s *Switch) Start() error { s.htlcForwarder() }) if err != nil { - s.Stop() + // We are already stopping so we can ignore the error. + _ = s.Stop() err = fmt.Errorf("unable to start htlc forwarder: %w", err) log.Errorf("%v", err) + return err } if err := s.reforwardResponses(); err != nil { - s.Stop() + // We are already stopping so we can ignore the error. + _ = s.Stop() log.Errorf("unable to reforward responses: %v", err) + return err } @@ -1798,6 +1803,7 @@ func (s *Switch) Start() error { // We are already stopping so we can ignore the error. _ = s.Stop() log.Errorf("unable to reforward resolutions: %v", err) + return err } diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index 30bb7ba877..1f9576ec81 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -1780,7 +1780,9 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) { cdb2, err := channeldb.Open(tempPath) require.NoError(t, err, "unable to reopen channeldb") - t.Cleanup(func() { cdb2.Close() }) + t.Cleanup(func() { + require.NoError(t, cdb2.Close()) + }) s2, err := initSwitchWithDB(testStartingHeight, cdb2) require.NoError(t, err, "unable reinit switch") @@ -3226,7 +3228,7 @@ func TestSwitchGetAttemptResultStress(t *testing.T) { // s.Stop() happens in the middle of GetAttemptResult series. // The value 10ms was found empirically - this time is needed // to expose the race condition (as a crash under -race) in the - // unfixed version of Switch, before GoroutineManager was added. + // version of Switch before GoroutineManager was added. time.Sleep(10 * time.Millisecond) require.NoError(t, s.Stop())