Skip to content

Infinite loop when using REPL with tight for loop of 300,000 #3972

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

Closed
sstchur opened this issue Nov 21, 2019 · 3 comments
Closed

Infinite loop when using REPL with tight for loop of 300,000 #3972

sstchur opened this issue Nov 21, 2019 · 3 comments

Comments

@sstchur
Copy link

sstchur commented Nov 21, 2019

Describe the bug
A simple tight-loop of 300,000 in the REPL causes a message from Svelte: "Infinite loop detected"

Logs
Not much in the logs (what is, is pasted below). Svelte shows a pink banner at the bottom of the page with a message "( ! ) Infinite loop detected"
Logs:
Console was cleared
bundler.js:25 running Svelte compiler version 3.15.0

To Reproduce
Simple use the Svelte REPL and paste the following into App.svelte

<script>
	for (let i = 0; i < 300000; i++)
	{
		
	}
	let name = 'The Avett Brothers!';
</script>

<h1>Hello {name}!</h1>

Occasionally, this won't be possible, and that's fine – we still appreciate you raising the issue. But please understand that Svelte is run by unpaid volunteers in their free time, and issues that follow these instructions will get fixed faster.

Expected behavior
Expect a tight-loop of 300000 to run to completion.

Stacktraces
If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

Stack trace goes here...

Information about your Svelte project:
-Chrome 78

  • Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc)
    Windows 10

  • Svelte version (Please check you can reproduce the issue with the latest release!)
    Whatever the REPL is using

  • Whether your project uses Webpack or Rollup
    N/A

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?
Pretty annoying for me b/c I'm trying to experiment with something that involves an array of about 300,000 elements.

Note: the more honest and specific you are here the more we will take you seriously.

Additional context
Add any other context about the problem here.
I think it's fairly clear from the repo -- nothing else interesting to report.

@Conduitry
Copy link
Member

This was recently changed as a way to address sveltejs/svelte-repl#40 - Maybe we could bump up the timeout before it bails (it's 100ms right now), but I doubt there's going to be any timeout that achieves the stated goal of avoiding unpleasant accidental hangs that won't have someone who says they need a synchronous blocking loop longer than that.

I'd argue that if you're doing something this intensive, you should probably take this out of the REPL and run your project locally, as you probably don't want to be recompiling your app on every keystroke in the editor anyway.

@sstchur
Copy link
Author

sstchur commented Nov 21, 2019

Thanks for the info. I can take it out of the REPL if that's the recommendation. I just hadn't realized that it would bomb out for this. If I run a tight loop in Chrome, it looks like it should take only about 2ms:

console.time('t');
for (let i = 0; i < 300000; i++)
{
}
console.timeEnd('t');
VM168:5 t: 2.0771484375ms

So I still have to wonder what's going on that 100ms isn't enough?

@Conduitry
Copy link
Member

Each iteration, the browser is now comparing Date.now() with the initial Date.now() when the loop was started and seeing whether 100ms has elapsed - which isn't much, but is a lot more than what is happening in your initial loop, which was nothing.

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

2 participants