fix script timeout bug (#170)
* fix an edge case where script timeout is too short and set even before VM starts execution * vm.StackObjects() -> v.IsStackEmpty()
This commit is contained in:
parent
1ac4090452
commit
8dc0d7b591
2 changed files with 7 additions and 12 deletions
|
@ -77,7 +77,6 @@ func (v *VM) Run() (err error) {
|
||||||
v.framesIndex = 1
|
v.framesIndex = 1
|
||||||
v.ip = -1
|
v.ip = -1
|
||||||
v.allocs = v.maxAllocs + 1
|
v.allocs = v.maxAllocs + 1
|
||||||
atomic.StoreInt64(&v.aborting, 0)
|
|
||||||
|
|
||||||
v.run()
|
v.run()
|
||||||
|
|
||||||
|
@ -95,11 +94,6 @@ func (v *VM) Run() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if stack still has some objects left
|
|
||||||
if v.sp > 0 && atomic.LoadInt64(&v.aborting) == 0 {
|
|
||||||
panic(fmt.Errorf("non empty stack after execution: %d", v.sp))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +115,7 @@ func (v *VM) run() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for atomic.LoadInt64(&v.aborting) == 0 {
|
for atomic.CompareAndSwapInt64(&v.aborting, 0, 0) {
|
||||||
v.ip++
|
v.ip++
|
||||||
|
|
||||||
switch v.curInsts[v.ip] {
|
switch v.curInsts[v.ip] {
|
||||||
|
@ -1008,9 +1002,9 @@ func (v *VM) run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Globals returns the global variables.
|
// IsStackEmpty tests if the stack is empty or not.
|
||||||
func (v *VM) Globals() []objects.Object {
|
func (v *VM) IsStackEmpty() bool {
|
||||||
return v.globals
|
return v.sp == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func indexAssign(dst, src objects.Object, selectors []objects.Object) error {
|
func indexAssign(dst, src objects.Object, selectors []objects.Object) error {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package runtime_test
|
package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
_runtime "runtime"
|
_runtime "runtime"
|
||||||
|
@ -250,8 +251,8 @@ func traceCompileRun(file *ast.File, symbols map[string]objects.Object, modules
|
||||||
}
|
}
|
||||||
trace = append(trace, fmt.Sprintf("\n[Globals]\n\n%s", strings.Join(formatGlobals(globals), "\n")))
|
trace = append(trace, fmt.Sprintf("\n[Globals]\n\n%s", strings.Join(formatGlobals(globals), "\n")))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err == nil && !v.IsStackEmpty() {
|
||||||
return
|
err = errors.New("non empty stack after execution")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue