Skip to content
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

ThreadPool: make sure no leaking threads are left behind in case of initialization failure #11061

Conversation

imotov
Copy link
Contributor

@imotov imotov commented May 8, 2015

Our ThreadPool constructor creates a couple of threads (scheduler and timer) which might not get shut down if the initialization of a node fails. A guice error might occur for example, which causes the InternalNode constructor to throw an exception. In this case the two threads are left behind, which is not a big problem when running es standalone as the error will be intercepted and the jvm will be stopped as a whole. It can become more of a problem though when running es in embedded mode, as we'll end up with lingering threads or testing an handling of initialization failures.

Closes #9107

@javanna
Copy link
Member

javanna commented May 8, 2015

I like it, LGTM

@imotov imotov added the v1.6.0 label May 8, 2015

TimeValue estimatedTimeInterval = settings.getAsTime("threadpool.estimated_time_interval", TimeValue.timeValueMillis(200));
this.estimatedTimeThread = new EstimatedTimeThread(EsExecutors.threadName(settings, "[timer]"), estimatedTimeInterval.millis());
this.estimatedTimeThread.start();
}

public void setNodeSettingsService(NodeSettingsService nodeSettingsService) {
nodeSettingsService.addListener(new ApplySettings());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add some safety that this method is called only once?

@jpountz
Copy link
Contributor

jpountz commented May 8, 2015

Left some suggestions but I like the change too!

@imotov
Copy link
Contributor Author

imotov commented May 8, 2015

@jpountz I pushed some changes. Could you take another look? Thanks!

@@ -91,13 +91,14 @@

private final EstimatedTimeThread estimatedTimeThread;

private volatile boolean settingsListenerIsSet = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need the volatile here?

@jpountz
Copy link
Contributor

jpountz commented May 8, 2015

LGTM, only one minor comment

…nitialization failure

Our ThreadPool constructor creates a couple of threads (scheduler and timer) which might not get shut down if the initialization of a node fails. A guice error might occur for example, which causes the InternalNode constructor to throw an exception. In this case the two threads are left behind, which is not a big problem when running es standalone as the error will be intercepted and the jvm will be stopped as a whole. It can become more of a problem though when running es in embedded mode, as we'll end up with lingering threads or testing an handling of initialization failures.

Closes elastic#9107
@imotov imotov force-pushed the issue-9107-move-thread-pool-initialization-out-of-guice branch from 389382f to 573caca Compare May 8, 2015 21:06
@imotov imotov merged commit 573caca into elastic:master May 8, 2015
@kevinkluge kevinkluge removed the review label May 8, 2015
@clintongormley clintongormley changed the title ThreadPool: make sure no leaking threads are left behind in case of i… ThreadPool: make sure no leaking threads are left behind in case of initialization failure May 15, 2015
@imotov imotov deleted the issue-9107-move-thread-pool-initialization-out-of-guice branch May 1, 2020 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ThreadPool: make sure no leaking threads are left behind in case of initialization failure
4 participants