diff --git a/youtubeapi/src/main/java/com/liskovsoft/youtubeapi/lounge/LoungeService.java b/youtubeapi/src/main/java/com/liskovsoft/youtubeapi/lounge/LoungeService.java index 6385a350e..33a7a1172 100644 --- a/youtubeapi/src/main/java/com/liskovsoft/youtubeapi/lounge/LoungeService.java +++ b/youtubeapi/src/main/java/com/liskovsoft/youtubeapi/lounge/LoungeService.java @@ -117,7 +117,18 @@ public void startListening(OnCommand callback) { e.printStackTrace(); break; } catch (Exception e) { + // NOTE: without a backoff delay here, a persistent failure (e.g. UnknownHostException + // right after the TV wakes from sleep, before WiFi/DNS is actually back up) turns this + // into a tight busy-loop retrying every few milliseconds, hammering CPU/DNS and never + // giving the network a chance to recover in between attempts. Sleeping between retries + // gives WiFi/DNS time to come back up, same as the normal-path delay above. Log.e(TAG, e.getMessage()); + try { + Thread.sleep(2_000); + } catch (InterruptedException interrupted) { + Log.e(TAG, "Oops. Stopping. Listening thread interrupted."); + break; + } // Continue to listen whichever is happening. } }