releaseExternalResources and akka.pattern.AskTimeoutException in multi-threaded environment #53
Description
We are using the Spark micro framework (http://sparkjava.com/) to create a prototype of our new web application. Spark allows you to define callbacks for routes invoked by client requests, e.g.,
get("/foo", (request, response) -> {
callback();
});
In one of the routes we employ parallec to concurrently retrieve the information (from another web service) we need to generate the HTTP response for a client request. We follow the procedure shown in the examples, i.e.,
ParallelTaskConfig config = new ParallelTaskConfig();
config.setActorMaxOperationTimeoutSec(35);
config.setTimeoutInManagerSec(900);
config.setTimeoutAskManagerSec(910);
ptb = pc.prepareHttpGet(String.format("/%s/$PARAMS", serviceConf.getServiceRoute())).saveResponseHeaders(respHeaders)
.setResponseContext(responseContext).setHttpHeaders(new ParallecHeader()
.addPair("Accept-Encoding","gzip")
.addPair("Accept",serviceConf.getMimeType())
.addPair("Accept-Language",this.language))
.setConfig(config)
.setConcurrency(100)
.setReplaceVarMapToSingleTargetSingleVar("PARAMS", identifierList, serviceConf.getServiceHost())
.setHttpPort(Integer.parseInt(serviceConf.getServicePort()));
ptb.execute(new ParallelResponseHandler());
pc.releaseExternalResources();
We noticed that when querying our web application with multiple concurrent client requests, i.e., one process is spawned for each concurrent request, we often encounter the following error message
Line 267: 84269 [Thread-16] ERROR io.parallec.core.task.ParallelTaskManager - Exception in sendTaskToExecutionManager akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://ParallecActorSystem/user/ExecutionManager-PT_14_20170110104948951_853663af-ce4#-964038860]] after [910000 ms] details akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://ParallecActorSystem/user/ExecutionManager-PT_14_20170110104948951_853663af-ce4#-964038860]] after [910000 ms]:
As it turns out this issue arises only when calling pc.releaseExternalResources() at the end of the callback. Our suspicion is that calling pc.releaseExternalResources() releases external resources that are still required by objects in one of the other spawned processes.
Is there anything we can do to avoid getting this error message? Is parallec "thread safe" in the sense that it can be used as described above? What would be the effect of not calling pc.releaseExternalResources()? Would the external resources get garbage collected?