New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 741656 link

Starred by 4 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

Eval in while loop causes crash

Reported by hakerh403@gmail.com, Jul 12 2017

Issue description

UserAgent: Nothing to see here.

Steps to reproduce the problem:
Run this code:
(a => {while(((a = (a | 0) + 1 | 0) | 0) !== 0)eval('')})(0)

What is the expected behavior?
Like in all other browsers, the script should complete after few seconds and return undefined.

What went wrong?
However, the script causes crash in chrome. The message says "chrome ran out of memory while displaying this webpage". I really don't see why does it causes a crash. Somewhere chrome is allocating memory, but not deallocating. In gecko engine the script completes without crash in just few seconds (9.82 on average).

Did this work before? No 

Chrome version: 59.0.3071.115 (Official Build) (64-bit) (cohort: Stable)  Channel: stable
OS Version: 
Flash Version: The flash is disabled
 

Comment 1 by junov@chromium.org, Jul 12 2017

Components: -Blink Blink>JavaScript>GC
My best guess is that the value returned by eval is not getting garbage collected.  Assigning to GC component for further investigation/triage.
Labels: Needs-Triage-M59 Needs-Bisect
Status: Untriaged (was: Unconfirmed)
I'm able to reproduce this issue on Latest Chrome Beta#60.0.3122.66 for 'Win7'.
Labels: -Needs-Bisect -Needs-Triage-M59 M-61
Able to reproduce this issue(as in crash@console.jpg) on Win-10 using chrome reported version #59.0.3071.115 and latest canary #61.0.3159.0.
Issue is not seen in OS-Mac and OS-Linux.

This is a non-regression issue as it is observed from M50 old builds. In M45 build, the code: (a => {while(((a = (a | 0) + 1 | 0) | 0) !== 0)eval('')})(0) neither returned undefined nor did it crash, rather it showed errors as in the attached screen shot(crash_M45@console.jpg).

Hence, marking it as untriaged to get more inputs from dev team.

Thanks...!!
crash_M45@console.JPG
156 KB View Download
crash@console.JPG
46.1 KB View Download
Cc: mvstan...@chromium.org
Owner: mlippautz@chromium.org
Status: Assigned (was: Untriaged)
memory sheriffs, PTAL
Cc: adamk@chromium.org
This is basically a 

while(true) eval('');

with 'a' being context allocated. At the first sight I don't see why we wouldn't run OOM here. 

Adam, any opinion on this one?
Cc: u...@chromium.org

Comment 7 by adamk@chromium.org, Jul 18 2017

I'm skeptical that there's anything actionable here, especially considering that it's an infinite loop (the only way I can imagine this "completing" in firefox is if the user allows the browser to kill the script).

Comment 8 by hakerh403@gmail.com, Jul 18 2017

@adamk. My original script is not infinite loop. According to the ES scep, integer overflow is not undefined behavior, so it will iterate exactly 2**32 iterations.

Comment 9 by adamk@chromium.org, Jul 18 2017

Ah, sorry, I didn't look closely enough at the original test case.

Re: #5, I actually don't know why this should run OOM. Yes, 'a' is context-allocated, but that's only one variable. The eval inside the loop will create a new JSFunction each time through, but I don't see what should be keeping them alive, so this does smell like there could be a GC issue to me.
I just checked locally on my machine. In d8 the script runs actually through in ~12min on my z840 without causing OOM. I assume that the script is killed before completing when executed in Chrome.

I profiled a much shorter run going until 2**28. The GC profile looks fine in the sense that we do not leak. Ideally there wouldn't be any allocations but the garbage that is created is cleaned up afaics.

$ time out/x64.release/d8 --trace-opt --prof script.js 
[marking 0x3e9f9a0c011 <JSFunction a (sfi = 0x3d2c8272cc29)> for optimized recompilation, reason: hot and stable, ICs with typeinfo: 7/7 (100%), generic ICs: 1/7 (14%)]
[compiling method 0x3e9f9a0c011 <JSFunction a (sfi = 0x3d2c8272cc29)> using TurboFan OSR]
[optimizing 0x3e9f9a0c011 <JSFunction a (sfi = 0x3d2c8272cc29)> - took 1.493, 0.647, 0.013 ms]
[marking 0x8bd9a3856e1 <JSFunction (sfi = 0x3d2c8272d3e1)> for optimized recompilation, reason: small function, ICs with typeinfo: 0/0 (100%), generic ICs: 0/0 (0%)]
[compiling method 0x8bd9a385729 <JSFunction (sfi = 0x3d2c8272d3e1)> using TurboFan]
[optimizing 0x8bd9a385729 <JSFunction (sfi = 0x3d2c8272d3e1)> - took 0.053, 0.162, 0.004 ms]
[completed optimizing 0x8bd9a385729 <JSFunction (sfi = 0x3d2c8272d3e1)>]

real	0m45.381s
user	0m51.672s
sys	0m1.800s

As #9 pointed out we do actually allocate JSFunctions which also causes GCs. However, if I interpret the performance profile correctly (profview), we spend quite some time in the runtime.

Top buckets are:
- 11% v8::internal::Runtime_ResolvePossiblyDirectEval
-  9% v8::internal::CompilationCacheTable::LookupEval
-  8% v8::internal::Factory::NewFunctionFromSharedFunctionInfo

I don't think that this is a GC issue.
Aaaand... the logfiles.
v8.json
5.3 MB View Download
eval-slowness.png
342 KB View Download
Cc: bmeu...@chromium.org
+bmeurer
Owner: mvstan...@chromium.org
Owner: mstarzinger@chromium.org
Not sure, but it seems that this may be related to
https://github.com/nodejs/node/issues/21142
and probably
https://github.com/nodejs/node/issues/19733
since the issue appears only when devtools are open. IIUC, the inspector retains a reference to eval'd code in case the user wants to inspect it (see the 4th comment on the second linked issue).

Sign in to add a comment