Skip to content
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

evenloop.Run hang with setInterval #69

Open
monkeyWie opened this issue Nov 24, 2023 · 3 comments
Open

evenloop.Run hang with setInterval #69

monkeyWie opened this issue Nov 24, 2023 · 3 comments

Comments

@monkeyWie
Copy link
Contributor

There is a setInterval that has not been cleared, it will be hang at evenloop.Run, see the code below:

func main() {
	loop := eventloop.NewEventLoop()

	var test goja.Callable
	loop.Run(func(vm *goja.Runtime) {
		vm.RunString(`
// Simulated users forget to clear setInterval
function leak(){
	setInterval(() => {
	},500)
}

async function test(){
	leak()
	return await new Promise((resolve, reject) => {
		setTimeout(() => {
			console.log('done')
			resolve('done')
		}, 1000)	
	})
}
`)
		test, _ = goja.AssertFunction(vm.Get("test"))
	})

	var (
		result goja.Value
		err    error
	)
        // hanged this line
	loop.Run(func(vm *goja.Runtime) {
		result, err = test(nil)
	})
	if err != nil {
		panic(err)
	}
	if vp, ok := result.Export().(*goja.Promise); ok {
		fmt.Println("result", vp.State(), vp.Result())
	}
}

How do I deal with this?

@bubbajoe
Copy link

My personal issues with this was setTimeout, so i'm not sure about setInterval; however, I think the design points to using something like RunOnLoop for something like this, but I didn't have any luck with that either.

I dealt with this issue by using the runtime outside of the callback function.

@matthewmueller
Copy link

matthewmueller commented Apr 20, 2024

Isn't this expected behavior? If there's a lingering setInterval, it would wouldn't exit in Node either.

@monkeyWie
Copy link
Contributor Author

monkeyWie commented May 6, 2024

Isn't this expected behavior? If there's a lingering setInterval, it would wouldn't exit in Node either.

Ya, but I can't got test() result, there's only one trick I can do with it now, check the promise state util it is finished, then stop the eventloop.

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

No branches or pull requests

3 participants