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

WatchDog shuts down ExecutorService from FixedExecutorProvider #870

Closed
chrisribble opened this issue Feb 13, 2020 · 3 comments · Fixed by #871 or #1158
Closed

WatchDog shuts down ExecutorService from FixedExecutorProvider #870

chrisribble opened this issue Feb 13, 2020 · 3 comments · Fixed by #871 or #1158
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@chrisribble
Copy link
Contributor

chrisribble commented Feb 13, 2020

#838 modified WatchDog to implement BackgroundResource and to track a Future for the work scheduled via the ExecutorService so that it can be cancelled. This is perfectly reasonable, but WatchDog.shutdown also calls ExecutorService.shutdown

This is problematic when you provide a FixedExecutorProvider to ClientContex.create since it uses the same ExecutorService instance (from the ExecutorProvider) for the WatchDog, which makes FixedExecutorProvider practically useless (since the ExecutorService that it provides can no longer be shared between clients, as shutting one down will shut down the ExecutorService)

I noticed this issue in our application while attempting to upgrade to google-cloud-core 1.92.5. We use java-pubsub 1.102.1 and we share the same ExecutorService among multiple dynamically-created Publisher instances. As soon as one is shut down, they all become inoperable since the underlying ExecutorService that they share is shut down.

Obviously, I could work around this by using an InstantiatingExecutorProvider, but I don't want to allocate new threads for every Publisher that my application creates (since the java-pubsub library requires the creation of a Publisher per topic and we publish to dynamically-created topics).

Possible solutions:

  1. Remove the call to executor.shutdown in WatchDog.shutdown
  2. Modify WatchDogProvider such that it accepts (and uses) an ExecutorProvider and checks ExecutorProvider.shouldAutoClose before calling shutdown on the ExecutorService
  3. Something else?
@igorbernstein2
Copy link
Contributor

I think the first option makes the most sense. ClientContext should be the primary owner of the executor

@rgrebski
Copy link
Contributor

rgrebski commented Jul 28, 2020

Should executor.shutdownNow() be removed from Watchdog.shutdownNow() as well ?

Since fix of #22, exactly this line, Subscriber.doStop is calling background resources shutdown, resulting with Watchdog.shutdownNow() being executed and ExecutorService being shutdown.

@igorbernstein2
Copy link
Contributor

Yes, that was an oversight. Thanks for pointing it out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.