Multi Threaded Access not allowed for JS

I try to do 2 subsequent httpGetRequests without success.

//this request initiates a phone call from my pbx to my mobile phone:
var result = actions.HTTP.sendHttpGetRequest("http://192.168.178.69/control/rcontrol?action=voipphone&name=OliverMobile");
//this request is supposed to hangup the call after 4 seconds
var resultHangUp = actions.HTTP.sendHttpGetRequest("http://192.168.178.69/control/rcontrol?action=voiphangup");

This results in the following error:

[ERROR] [enhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.TimeoutException: Total timeout 5000 ms elapsed

This error appears even if I set the delay value to 4000.
If I try to create a timer which hangs up before the timeout happens like this:

setTimeout(() => {
  var resultHangUp = actions.HTTP.sendHttpGetRequest("http://192.168.178.69/control/rcontrol?action=voiphangup");
  console.log(rule, "Hang up:",resultHangUp);
}, 4000);
var result = actions.HTTP.sendHttpGetRequest("http://192.168.178.69/control/rcontrol?action=voipphone&name=OliverMobile");

I get an error message that multi threaded access is not allowed for JS

[ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'Alarme': Failed to execute action: 2(Multi threaded access requested by thread Thread[OH-rule-Alarme-1,5,Configuration Admin Service] but is not allowed for language(s) js.)

Any idea how do I need to change my script?

That error occurs when, for a single rule, more than one thread is attempting to access data from that rule at the same time. GraalVM JS does not support that so that exception is thrown.

There are locks built into the add-on that prevents that sort of thing from happening most of the time but not all of the time.d

What I suspect is happening is the first sendHttpGetRequest call isn’t returning so the second call doesn’t ever get a chance to run and eventually the first call times out and aborts.

For the second version of the code, the first sendHttpGetRequest (the one after the setTimeout) is still running when the timer goes off resulting in a multithreaded access error.

Ultimately, I’m not sure you can do this from a single rule if that is indeed the case. What you might need to do is trigger a second rule to issue the request to hang up the call.

1 Like