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

fix: Watchdog does not does not wait for executor to shutdown on awaitTermination #1884

Closed
wants to merge 6 commits into from

Conversation

blakeli0
Copy link
Contributor

@blakeli0 blakeli0 commented Nov 15, 2022

fixes: #1858

Watchdog does not wait for executor to shutdown on awaitTermination. Instead, use Phaser to track the lifecycle of each run() execution, wait for the Phaser to proceed to next phase(which is terminated phase in our case) in awaitTermination and use phaser.isTerminated() to determine if Watchdog is terminated or not.

…ng if the executor is provided by ExecutorProvider.
@blakeli0 blakeli0 marked this pull request as ready for review December 2, 2022 18:02
@blakeli0 blakeli0 requested review from a team as code owners December 2, 2022 18:02
@sonarcloud
Copy link

sonarcloud bot commented Dec 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

90.9% 90.9% Coverage
0.0% 0.0% Duplication

@blakeli0 blakeli0 changed the title fix: [Approach 3]Watchdog does not shut down executor on client closing if the executor is provided by ExecutorProvider. fix: Watchdog does not does not wait for executor to shutdown on awaitTermination Dec 2, 2022
}

@Override
public void shutdownNow() {
future.cancel(true);
// Unregister the main thread
phaser.arriveAndDeregister();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to avoid double calls:

if (future.cancel(true)) {
phaser.arriveAndDeregister();

}

@@ -134,26 +143,37 @@ private void runUnsafe() {
@Override
public void shutdown() {
future.cancel(false);
// Unregister the main thread
phaser.arriveAndDeregister();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to avoid double calls:

if (future.cancel(true)) {
phaser.arriveAndDeregister();

}

Copy link
Contributor

@igorbernstein2 igorbernstein2 left a comment

Choose a reason for hiding this comment

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

lgtm after comment

@meltsufin meltsufin added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jan 11, 2023
@meltsufin
Copy link
Member

meltsufin commented Jan 11, 2023

@igorbernstein2 I don't think this PR is still relevant because we went with: #1890. But we can wait for @blakeli0 to confirm.

Update: I see it was planned as a further improvement to #1890. So never mind.

@suztomo
Copy link
Member

suztomo commented Feb 10, 2023

Closing this in favor of googleapis/sdk-platform-java#1337

@suztomo suztomo closed this Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watchdog waits on executor shutdown in awaitTermination, even if ExecutorProvider has shouldAutoClose == false
4 participants