Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
fix(logging): catch and log exceptions in Watchdog runnable to ensure…
Browse files Browse the repository at this point in the history
… it never stops running (#1036)

* Catch and log exceptions in Watchdog runnable to ensure it never stops running

* fix: fix mismerge

* fix: mismerge again

in master, `@InternalApi` was changed to `@BetaApi`

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
justinuang and chingor13 committed Jun 10, 2020
1 parent e63cab8 commit 092007b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gax/src/main/java/com/google/api/gax/rpc/Watchdog.java
Expand Up @@ -40,6 +40,8 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.threeten.bp.Duration;
Expand All @@ -61,6 +63,8 @@
*/
@BetaApi
public final class Watchdog implements Runnable, BackgroundResource {
private static final Logger LOG = Logger.getLogger(Watchdog.class.getName());

// Dummy value to convert the ConcurrentHashMap into a Set
private static Object PRESENT = new Object();
private final ConcurrentHashMap<WatchdogStream, Object> openStreams = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -111,6 +115,14 @@ public <ResponseT> ResponseObserver<ResponseT> watch(

@Override
public void run() {
try {
runUnsafe();
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Caught throwable in periodic Watchdog run. Continuing.", t);
}
}

private void runUnsafe() {
Iterator<Entry<WatchdogStream, Object>> it = openStreams.entrySet().iterator();

while (it.hasNext()) {
Expand Down

0 comments on commit 092007b

Please sign in to comment.