-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix Stackdriver's shutdown behavior #4358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0bbe0bb
3dd1e8b
e80d556
9a80c05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ public void start(ThreadFactory threadFactory) { | |
logger.error("unable to start stackdriver, service settings are not available"); | ||
} | ||
else { | ||
shutdownClientIfNecessary(true); | ||
try { | ||
this.client = MetricServiceClient.create(metricServiceSettings); | ||
super.start(threadFactory); | ||
|
@@ -138,11 +139,57 @@ public void start(ThreadFactory threadFactory) { | |
|
||
@Override | ||
public void stop() { | ||
if (client != null) | ||
client.shutdownNow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this from here will potentially be problematic (a resource leak) if the registry is stopped and started multiple times. If it is only stopped as part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
super.stop(); | ||
} | ||
Comment on lines
140
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to have an overridden method that just calls its There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for taking a look. Indeed we don't need to override if we aren't doing anything but calling the super here. I'll take care of it in a polish commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it looks like removing the override breaks binary compatibility even if it is source compatible, which @dimovelev found out when they tried to remove it and added it back. |
||
|
||
@Override | ||
public void close() { | ||
try { | ||
super.close(); | ||
} | ||
finally { | ||
shutdownClientIfNecessary(false); | ||
} | ||
} | ||
|
||
protected void shutdownClientIfNecessary(final boolean quietly) { | ||
if (client != null) { | ||
if (!client.isShutdown()) { | ||
try { | ||
client.shutdownNow(); | ||
final boolean terminated = client.awaitTermination(10, TimeUnit.SECONDS); | ||
if (!terminated) { | ||
logger.warn("The metric service client failed to terminate within the timeout"); | ||
} | ||
} | ||
catch (final RuntimeException e) { | ||
if (quietly) { | ||
logger.warn("Failed to shutdown the metric service client", e); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
catch (final InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
return; | ||
} | ||
} | ||
try { | ||
client.close(); | ||
} | ||
catch (final RuntimeException e) { | ||
if (quietly) { | ||
logger.warn("Failed to close metric service client", e); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
client = null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void publish() { | ||
if (client == null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary if nothing is done with the client in
stop
. The question is: should something be done in stop or only in close? We haven't been very clear about what should happen where (no JavaDocs). I'll open a separate issue to clear that up.It's a bit wasteful of resources to not shutdown the client when a user calls
stop
on the registry, but in terms of publishing it shouldn't be an issue because the scheduled call topublish
won't happen afterstop
is called untilstart
is called again. Looking at other implementations, we do the same in WavefrontMeterRegistry - nothing special instop
and close the client on close aftersuper.close()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remembered now the issue I was pointing out in my previous review. We don't want to replace the client without shutting down the old one and making it eligible for garbage collection. Therefore having this line here should prevent that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As promised, I opened #4632 to track clarifying stop semantics.