-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule Node Scripts: delight-nashorn-sandbox ScriptCPUAbuseException #11077
Comments
Attach a sample code that causes an error in the script node of the rules engine. |
We are experiencing the same issue, most of our MQTT Integrations are showing Errors due to this issue. Changing the USE_LOCAL_JS_SANDBOX to "false" resolved it (temporarly) but at what other possible issues? |
The sandbox protects your instance from malicious scripts. Therefore, you must ensure that there are no faulty scripts in your converters and rule chains that could cause processing issues. Sendbox also protects from infinite loops or JS injections. JS executors will fix this issue since it runs on nodeJS and doesn't use nashorn. I can't ensure that JS executors support ES6+, but they support a lot more fucntions than nashorn. JS executors use kafka to communicate with thingsboard . So for minimal deployment you will need thingsboard monolith, kafka + zookeeper or kafka kraft, js executors. To connect remote js executors do the following (example for installation as ubuntu service):
Create docker-compose.yml file: version: '3.2'
services:
kafka:
restart: always
image: bitnami/kafka:3.5.2
ports:
- 9092:9092 #to localhost:9092 from host machine
- 9093 #for Kraft
- 9094 #to kafka:9094 from within Docker network
environment:
ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_CFG_LISTENERS: "OUTSIDE://:9092,CONTROLLER://:9093,INSIDE://:9094"
KAFKA_CFG_ADVERTISED_LISTENERS: "OUTSIDE://localhost:9092,INSIDE://kafka:9094"
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT,CONTROLLER:PLAINTEXT"
KAFKA_CFG_INTER_BROKER_LISTENER_NAME: "INSIDE"
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
KAFKA_CFG_PROCESS_ROLES: "controller,broker" #KRaft
KAFKA_CFG_NODE_ID: "0" #KRaft
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: "CONTROLLER" #KRaft
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka:9093" #KRaft
volumes:
- kafka-data:/bitnami
tb-js-executor:
restart: always
image: "thingsboard/tb-js-executor:3.7.0"
scale: 5
environment:
REMOTE_JS_EVAL_REQUEST_TOPIC: js_eval.requests
LOGGER_LEVEL: info
LOG_FOLDER: logs
LOGGER_FILENAME: tb-js-executor-%DATE%.log
DOCKER_MODE: "true"
SCRIPT_BODY_TRACE_FREQUENCY: 1000
NODE_OPTIONS: "--max-old-space-size=200"
MAX_ACTIVE_SCRIPTS: "4000"
TB_QUEUE_TYPE: kafka
TB_QUEUE_KAFKA_COMPRESSION: "gzip"
TB_KAFKA_BATCH_SIZE: "128"
TB_KAFKA_SERVERS: kafka:9094
volumes:
kafka-data:
driver: local Start docker compose and restart thingsboard to apply new setthings. |
Any workaround, met the same issue. |
@hkecho see comments above: #11077 (comment) #11077 (comment) |
This is still an issue with 3.7.0. |
Patch for sandbox available that passes the provided example, see javadelight/delight-nashorn-sandbox#151 (comment) Note issue may still appear with some complex scripts. Any further issues, please reach out! |
Note due to the great work for @busterace there is a version available with a better fix that also generally improves performance by removing the need for running the regular expressions by using an AST library: <dependency>
<groupId>org.javadelight</groupId>
<artifactId>delight-nashorn-sandbox</artifactId>
<version>0.5.0</version>
</dependency> |
Bugfix implemented in version 3.8.0 |
Describe the bug
Since 3.7.0 (lengthy) rule-node scripts which were working in 3.6.4 now fail:
Can't compile script: delight.nashornsandbox.exceptions.ScriptCPUAbuseException: Regular expression running for too many iterations. The operation could NOT be gracefully interrupted.
This appears to be directly related to a commit where delight-nashorn-sandbox version is changed from 0.2.1 to 0.4.2 cd722a1
delight-nashorn-sandbox has an open bug, introduced at 0.3.1, which appears to fail-to-parse certain structures: javadelight/delight-nashorn-sandbox#151
Your Server Environment
Your Client Environment
To Reproduce
Steps to reproduce the behavior:
Additional context
As a workaround, changing environment the variable in thingsboard.conf
USE_LOCAL_JS_SANDBOX = false
appears to mitigate the error. However, we dont want to do this in production.The text was updated successfully, but these errors were encountered: