Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/main/java/me/kavin/piped/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ public void run() {

System.out.println("FeedRefresh: " + channelIds.size() + " channels, one every " + delay + "ms");

int consecutiveFailures = 0;

Comment on lines +279 to +280

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the failure streak across full refresh passes.

consecutiveFailures is recreated on each outer while iteration, so a streak that spans the end of one pass and the start of the next is lost. That means instances with fewer than 5 subscribed channels can fail forever without ever hitting the new backoff.

Proposed fix
         if (Constants.FEED_REFRESH)
             Thread.ofVirtual().name("feed-refresh").start(() -> {
+                int consecutiveFailures = 0;
                 while (true) {
                     try {
                         List<String> channelIds;
@@
-                        int consecutiveFailures = 0;
-
                         for (String channelId : channelIds) {
                             try {
                                 var info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);

Also applies to: 290-299

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/me/kavin/piped/Main.java` around lines 279 - 280, The failure
streak in the refresh loop is being reset each time the outer while pass
restarts, so move consecutiveFailures to a scope that survives across full
refresh passes in Main’s refresh logic. Update the handling around the loop that
processes subscribed channels so the same counter is reused across iterations,
and keep the backoff reset only when a successful refresh occurs; this ensures
the streak can cross pass boundaries and trigger the intended delay.

for (String channelId : channelIds) {
try {
var info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
Expand All @@ -285,8 +287,16 @@ public void run() {
Multithreading.runAsync(() -> ChannelHelpers.federateChannelInfo(info));
if (tabInfo != null)
ChannelHelpers.updateChannelVideos(info, tabInfo);
consecutiveFailures = 0;
} catch (Exception e) {
consecutiveFailures++;
ExceptionHandler.handle(e);
if (consecutiveFailures >= 5) {
System.out.println("FeedRefresh: " + consecutiveFailures
+ " consecutive failures, likely rate-limited — pausing 5 minutes");
Thread.sleep(TimeUnit.MINUTES.toMillis(5));
consecutiveFailures = 0;
}
}
Thread.sleep(delay);
}
Expand Down
Loading