Comments (9)
The first panic is on the line:
op := program.Bytecode[vm.ip]
This means that the instruction pointer points to a wrong address.
But this is strange, as a few lines above we have check:
for vm.ip < len(program.Bytecode) {
if vm.debug {
<-vm.step
}
op := program.Bytecode[vm.ip]
Very interesting.
Is it possible to add a wrapper with recover and log the executed expression?
from expr.
Also, could you make sure that you don't reuse VM in different threads?
from expr.
I added wrapper and caught the panic once again (same stacktrace).
Executed expression:
Data.Code == 'XXX' && Parameters.Date.Unix() < ToUnix('2024-01-01')
So, the environment is something like this:
type env struct {
Data *DataStruct
Parameters *ParametersStruct
}
type DataStruct struct {
Code string
}
type ParametersStruct struct {
Date time.Time
}
func (e *env) ToUnix(rawDate string) int64 {
t, err := time.Parse("2006-01-02", rawDate)
if err != nil {
panic("invalid rawDate")
}
return t.Unix()
}
And ToUnix
function is marked as expr.ConstExpr
(also there are expr.Optimize(true)
and expr.AsBool()
options).
I will keep my eye on it to prove that panics happen only for this expression.
I checked the code and seems highly unlikely that VM is being used in different threads.
from expr.
The code looks ok. Lets true to take a look at what program (already compiled) is executed during panic.
Please, log the program as JSON, and as program.Disassemble()
.
from expr.
Should getting the program as JSON be done as something like this json.Marshal(vm.Program.Source)
?
from expr.
The whole program. Or some sort of other dump technics you can find out.
from expr.
@Bychin any news on the problem?
from expr.
@antonmedv so I wasn't able to reproduce the problems after a little change.
So previously I was using the VM like this:
type Evaluator struct {
v *vm.VM
}
func (e *Evaluator) Evaluate() error {
// reuse the same vm instance for performance gain
v := e.v
if v == nil {
v = &vm.VM{}
}
... := v.Run(...)
return nil
}
// WithReusableVM reuses the same vm instance for performance gain.
// It will make the engine not thread safe.
func (e *Evaluator) WithReusableVM() {
e.v = &vm.VM{}
}
evaluator := &Evaluator{}
if reuseVM {
evaluator.WithReusableVM() // <- this thing caused the problem
}
evaluator.Evaluate()
evaluator
is used in a single thread, but as soon as I stopped reusing VM
the problem was gone. I checked the code of v.Run
method and I can see that the inner state of VM
is cleared before the actual execution, so I don't know where to investigate next.
from expr.
I will close this issue as it not a problem any more. Feel free to create another issue if someone encounters a panic in vm.
from expr.
Related Issues (20)
- Constant 1 overflows int64 when compiling expressions with int64 type parameters HOT 2
- Feature request: UNKNOWN type HOT 6
- trying to understand expr lang more, is there anything that expression can do that goja / otto cant and vice versa? HOT 2
- Feature request:two builtin array functions HOT 2
- it is really fast. question on language compatibility issue... HOT 2
- Add `flatten()` builtin HOT 3
- how to implement the 'like' bool expression using expr HOT 1
- Add better documentation about `min` `max` builtins
- invalid char escape HOT 1
- *vm.Program Not Safe HOT 1
- Support matches for bytes HOT 1
- Question: Is there planned support for iterator in version 1.23? HOT 6
- pass nil to interface method get runtime error "Call using interface {} as type *int (1:5)"
- expr.AsKind not work? HOT 4
- Language support for VSCode? HOT 5
- Double definition of Variable/Function not usable anymore. HOT 2
- Cannot use map[string]interface {} as argument (type main.Env) to call dump HOT 5
- Functions defined on the struct are bidden to the Env they were compiled with HOT 6
- Create custom function with many arguments HOT 1
- Feature request: allow multiple expressions in a single program HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expr.