Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,10 @@ func AutomaticallyTestChannels() {
time.Sleep(10 * time.Minute)
continue
}
frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
for {
frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
time.Sleep(time.Duration(frequency) * time.Minute)
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
Comment on lines +626 to +628

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Sleep-before-test violates the "immediate initial test" objective.

The current implementation retrieves the frequency and immediately sleeps (lines 626-627) before performing any test. This means:

  1. No immediate initial test: When the inner loop starts, it waits the full interval before the first test runs, contradicting the PR description which explicitly states "Add immediate initial test execution before the ticker starts."
  2. Delayed first execution: If the frequency is 60 minutes, operators must wait a full hour before the first test, even though the feature was just enabled.

The correct flow should be: test → sleep → test, not sleep → test. Move the sleep to the end of the loop:

 for {
   frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
-  time.Sleep(time.Duration(frequency) * time.Minute)
   common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
   common.SysLog("automatically testing all channels")
   _ = testAllChannels(false)
   common.SysLog("automatically channel test finished")
   if !operation_setting.GetMonitorSetting().AutoTestChannelEnabled {
     break
   }
+  time.Sleep(time.Duration(frequency) * time.Minute)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
time.Sleep(time.Duration(frequency) * time.Minute)
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
for {
frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
common.SysLog("automatically testing all channels")
_ = testAllChannels(false)
common.SysLog("automatically channel test finished")
if !operation_setting.GetMonitorSetting().AutoTestChannelEnabled {
break
}
time.Sleep(time.Duration(frequency) * time.Minute)
}
🤖 Prompt for AI Agents
In controller/channel-test.go around lines 626 to 628, the loop currently reads
the frequency and immediately calls time.Sleep before performing the test, which
prevents an immediate initial test; change the loop order so the test logic runs
first, then call time.Sleep(time.Duration(frequency) * time.Minute) at the end
of the loop (keeping frequency retrieval as-is or validating it once outside the
loop), and ensure you handle zero/negative frequency (skip sleeping or use a
sensible default) so the execution sequence becomes: test → sleep → test.

common.SysLog("automatically testing all channels")
_ = testAllChannels(false)
common.SysLog("automatically channel test finished")
Expand Down