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

Executor thread not set after <some value> ms - intermittently #75

Open
pradeepKaatnam opened this issue Feb 7, 2019 · 2 comments
Open

Comments

@pradeepKaatnam
Copy link

pradeepKaatnam commented Feb 7, 2019

Hey

I am getting into this error Executor thread not set after ms intermittently. I have gone through the code and I came up with a theory where this can happen. This happens when threadToMonitor variable is null in run() method of ThreadMonitor. The reason can be below:

final JsEvaluator evaluator = getEvaluator(op);
executor.execute(evaluator);
evaluator.runMonitor();

Lets say the executor is created with a max pool size of 5 and there are some 100 incoming requests. Here is there is a chance for some requests to be waiting in the queue of executor. Since it is asynchronous, evaluator's runMonitor() method will be called irrespective of whether its corresponding thread is initiated or not. There is wait time of maxCPUTime / MILI_TO_NANO for the threadToMonitor to be set by the executor api. It might be because previously long running threads will get terminated after their maxCPUTime because of threadToMonitor.interrupt(). Here if the thread doesn't goes down after interrupt then it is waiting for 50 more milli seconds and doing a hard shutdown().

So in the case of hard shutdown there is chance of this exception as it is waiting for only maxCPUTime and not for maxCPUTime + 50(the extra time taken for hard shutdown)

synchronized (monitor) {
    if (threadToMonitor == null) {
	monitor.wait(maxCPUTime / MILI_TO_NANO);
    }
}
if (threadToMonitor == null) {
	throw new IllegalStateException("Executor thread not set after " + maxCPUTime / MILI_TO_NANO + " ms");
}

To conclude, in the run() method of ThreadMonitor class, there should be some additional buffer time i.e.

void run() {
    try {
	// wait, for threadToMonitor to be set in JS evaluator thread
	synchronized (monitor) {
		if (threadToMonitor == null) {
			monitor.wait((maxCPUTime + 50) / MILI_TO_NANO);
		}
	}
	if (threadToMonitor == null) {
		throw new IllegalStateException("Executor thread not set after " + maxCPUTime / MILI_TO_NANO + " ms");
	}

Let me know your thoughts.

@srinivasarajuch
Copy link

@mxro This is possible issue, I can raise PR for this. Please let me know you thoughts

srinivasarajuch pushed a commit to srinivasarajuch/delight-nashorn-sandbox that referenced this issue Feb 11, 2019
…ntly javadelight#75

> Fixed issue my adding additional 100ms delay to get the thread monitor instance
@mxro
Copy link
Collaborator

mxro commented Feb 11, 2019

Thank you for the PR! Code is merged in released with version 0.1.21 which should be available via Maven Central shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants