Open lunacrafts opened 4 months ago
These two tickets are not related, but I decided to post it here as I assume they are both solvable within the same area of the code.
Turns out this issue is caused by Goja runtime reuse: https://github.com/dop251/goja/issues/205. Will try to find a way to address this or at least document it.
Simple way to reproduce it:
input:
generate:
count: 0
interval: 250ms
mapping: |
root = {}
processors:
- javascript:
code: |
let foobar = benthos.v0_msg_as_structured();
benthos.v0_msg_set_structured(foobar);
- log:
message: ${! error() }
output:
stdout: {}
This will start printing SyntaxError: Identifier 'foobar' has already been declared at main.js:1:1(0)
as soon as runtimes from the pool get reused.
One workaround is to scope the script:
(function() {
let foobar = benthos.v0_msg_as_structured();
benthos.v0_msg_set_structured(foobar);
})();
According to this blog post, it should be fine to have all these anonymous functions created since the goja runtime garbage collector can clean them up. We might want to consider doing this by default internally.
I am encountering an issue with running a JavaScript processor in Benthos. The processor's intended function is to delete a specific property (xxx) from incoming JSON objects. However, the property deletion behaves inconsistently, resulting in unreliable processing. The logs show that the property xxx is sometimes deleted and sometimes not, with no apparent pattern. Below is a snippet of the log output, demonstrating the inconsistent behavior:
logs
benthos.yaml
Code is deployed to minikube via helm chart & Pulumi. Memory or any other resources are not exceeded
helm & pulumi