Add script invocation result size check to remote JS executor

This commit is contained in:
ViacheslavKlimov 2022-10-03 15:22:11 +03:00
parent a2c830ce8a
commit 8d735f4886
3 changed files with 16 additions and 3 deletions

View File

@ -43,6 +43,7 @@ const useSandbox = config.get('script.use_sandbox') === 'true';
const maxActiveScripts = Number(config.get('script.max_active_scripts'));
const slowQueryLogMs = Number(config.get('script.slow_query_log_ms'));
const slowQueryLogBody = config.get('script.slow_query_log_body') === 'true';
const maxResultSize = Number(config.get('js.max_result_size'));
export class JsInvokeMessageProcessor {
@ -164,9 +165,19 @@ export class JsInvokeMessageProcessor {
(script) => {
this.executor.executeScript(script, invokeRequest.args, invokeRequest.timeout).then(
(result) => {
if (result.length <= maxResultSize) {
const invokeResponse = JsInvokeMessageProcessor.createInvokeResponse(result, true);
this.logger.debug('[%s] Sending success invoke response, scriptId: [%s]', requestId, scriptId);
this.sendResponse(requestId, responseTopic, headers, scriptId, undefined, invokeResponse);
} else {
let err = {
name: 'Error',
message: 'script invocation result exceeds maximum allowed size of ' + maxResultSize + ' symbols'
}
const invokeResponse = JsInvokeMessageProcessor.createInvokeResponse("", false, RUNTIME_ERROR, err);
this.logger.debug('[%s] Script invocation result exceeds maximum allowed size of %s symbols, scriptId: [%s]', requestId, maxResultSize, scriptId);
this.sendResponse(requestId, responseTopic, headers, scriptId, undefined, invokeResponse);
}
},
(err: any) => {
let errorCode;

View File

@ -20,6 +20,7 @@ http_port: "HTTP_PORT" # /livenessProbe
js:
response_poll_interval: "REMOTE_JS_RESPONSE_POLL_INTERVAL_MS"
max_result_size: "JS_MAX_RESULT_SIZE"
kafka:
bootstrap:

View File

@ -20,6 +20,7 @@ http_port: "8888" # /livenessProbe
js:
response_poll_interval: "25"
max_result_size: "300000"
kafka:
bootstrap: