Add script invocation result size check to remote JS executor
This commit is contained in:
		
							parent
							
								
									a2c830ce8a
								
							
						
					
					
						commit
						8d735f4886
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,7 @@ http_port: "8888" # /livenessProbe
 | 
			
		||||
 | 
			
		||||
js:
 | 
			
		||||
  response_poll_interval: "25"
 | 
			
		||||
  max_result_size: "300000"
 | 
			
		||||
 | 
			
		||||
kafka:
 | 
			
		||||
  bootstrap:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user