Browse Source

Merge pull request #6905 from volodymyr-babak/js-timeout-fix

[WIP][3.4] Js timeout fix
pull/6910/head
Andrew Shvayka 4 years ago
committed by GitHub
parent
commit
9d199e3f0b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      application/src/main/java/org/thingsboard/server/service/script/AbstractNashornJsInvokeService.java
  2. 16
      application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java
  3. 2
      application/src/main/resources/thingsboard.yml

2
application/src/main/java/org/thingsboard/server/service/script/AbstractNashornJsInvokeService.java

@ -159,6 +159,8 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
} else {
return ((Invocable) engine).invokeFunction(functionName, args);
}
} catch (ScriptException e) {
throw new ExecutionException(e);
} catch (Exception e) {
onScriptExecutionError(scriptId, e, functionName);
throw new ExecutionException(e);

16
application/src/main/java/org/thingsboard/server/service/script/RemoteJsInvokeService.java

@ -57,6 +57,9 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
@Value("${queue.js.max_requests_timeout}")
private long maxRequestsTimeout;
@Value("${queue.js.max_exec_requests_timeout:2000}")
private long maxExecRequestsTimeout;
@Getter
@Value("${js.remote.max_errors}")
private int maxErrors;
@ -170,7 +173,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
.setScriptIdMSB(scriptId.getMostSignificantBits())
.setScriptIdLSB(scriptId.getLeastSignificantBits())
.setFunctionName(functionName)
.setTimeout((int) maxRequestsTimeout)
.setTimeout((int) maxExecRequestsTimeout)
.setScriptBody(scriptBody);
for (Object arg : args) {
@ -197,7 +200,6 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
@Override
public void onFailure(Throwable t) {
onScriptExecutionError(scriptId, t, scriptBody);
if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
queueTimeoutMsgs.incrementAndGet();
}
@ -212,8 +214,14 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
return invokeResult.getResult();
} else {
final RuntimeException e = new RuntimeException(invokeResult.getErrorDetails());
onScriptExecutionError(scriptId, e, scriptBody);
log.debug("[{}] Failed to compile script due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
if (JsInvokeProtos.JsInvokeErrorCode.TIMEOUT_ERROR.equals(invokeResult.getErrorCode())) {
onScriptExecutionError(scriptId, e, scriptBody);
queueTimeoutMsgs.incrementAndGet();
} else if (JsInvokeProtos.JsInvokeErrorCode.COMPILATION_ERROR.equals(invokeResult.getErrorCode())) {
onScriptExecutionError(scriptId, e, scriptBody);
}
queueFailedMsgs.incrementAndGet();
log.debug("[{}] Failed to invoke function due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
throw e;
}
}, callbackExecutor);

2
application/src/main/resources/thingsboard.yml

@ -1051,6 +1051,8 @@ queue:
max_eval_requests_timeout: "${REMOTE_JS_MAX_EVAL_REQUEST_TIMEOUT:60000}"
# JS max request timeout
max_requests_timeout: "${REMOTE_JS_MAX_REQUEST_TIMEOUT:10000}"
# JS execution max request timeout
max_exec_requests_timeout: "${REMOTE_JS_MAX_EXEC_REQUEST_TIMEOUT:2000}"
# JS response poll interval
response_poll_interval: "${REMOTE_JS_RESPONSE_POLL_INTERVAL_MS:25}"
rule-engine:

Loading…
Cancel
Save