Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

fatal error: all goroutines are asleep - deadlock! #1

Open
moisespsena opened this issue Sep 9, 2020 · 1 comment
Open

fatal error: all goroutines are asleep - deadlock! #1

moisespsena opened this issue Sep 9, 2020 · 1 comment

Comments

@moisespsena
Copy link

moisespsena commented Sep 9, 2020

Hello!
This code has be failure.

package main

import (
	"github.com/ozanh/tengox"

	"github.com/d5/tengo"
	"github.com/d5/tengo/stdlib"
)

func main() {
	// create a new Script instance
	script := tengox.NewScript([]byte(`
fmt := import("fmt")

f := func(msg) {
	return "Message: " + msg
}

main := func() {
	fmt.println(go_func(f))
}
`))
	var c *tengox.Compiled
	script.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...))
	script.Add("go_func", func(args ...tengo.Object) (tengo.Object, error) {
		ret, err := c.Call(args[0], "hello!")
		if err != nil {
			return nil, err
		}
		return tengo.FromInterface(ret)
	})
	var err error

	if c, err = script.CompileRun(); err != nil {
		panic(err)
	}
	_, err = c.CallByName("main")
	panic(err)
}

Output:

fatal error: all goroutines are asleep - deadlock!
@ozanh
Copy link
Owner

ozanh commented Sep 13, 2020

Hi, it looks like the result is what I addressed at this post d5/tengo#275 (comment)
You should not run tengo compiled function from a Go callable due to serialization with a mutex.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants