Improve error handling and logging in polling thread of OpenViduEventManager

v2compatibility
pabloFuente 2026-03-26 13:09:06 +01:00
parent 2d319ac131
commit 3f37b61b0d
1 changed files with 16 additions and 9 deletions

View File

@ -126,6 +126,7 @@ public class OpenViduEventManager {
} }
this.pollingThread = new Thread(() -> { this.pollingThread = new Thread(() -> {
try {
while (!this.isInterrupted.get()) { while (!this.isInterrupted.get()) {
this.getEventsFromBrowser(); this.getEventsFromBrowser();
this.emitEvents(); this.emitEvents();
@ -135,7 +136,11 @@ public class OpenViduEventManager {
} }
} }
log.info("Polling thread is now interrupted!"); log.info("Polling thread is now interrupted!");
} catch (Exception e) {
log.error("Polling thread crashed: {}", e.getMessage());
} finally {
this.pollingLatch.countDown(); this.pollingLatch.countDown();
}
}); });
this.pollingThread.setUncaughtExceptionHandler(h); this.pollingThread.setUncaughtExceptionHandler(h);
this.pollingThread.start(); this.pollingThread.start();
@ -261,7 +266,9 @@ public class OpenViduEventManager {
public void resetEventThread(boolean clearData) throws InterruptedException { public void resetEventThread(boolean clearData) throws InterruptedException {
this.stopPolling(true, clearData); this.stopPolling(true, clearData);
this.pollingLatch.await(); if (!this.pollingLatch.await(10, TimeUnit.SECONDS)) {
log.warn("Polling thread did not stop within 10 seconds");
}
this.execService.shutdownNow(); this.execService.shutdownNow();
this.execService.awaitTermination(10, TimeUnit.SECONDS); this.execService.awaitTermination(10, TimeUnit.SECONDS);
this.execService = Executors.newCachedThreadPool(); this.execService = Executors.newCachedThreadPool();