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

[Bug] Memory leak when evaluating #21345

Closed
hanfeige opened this issue Feb 14, 2023 · 6 comments · Fixed by #21358
Closed

[Bug] Memory leak when evaluating #21345

hanfeige opened this issue Feb 14, 2023 · 6 comments · Fixed by #21358
Assignees
Labels

Comments

@hanfeige
Copy link

hanfeige commented Feb 14, 2023

Context:

Playwright Version: 1.27.2
Operating System: Windows
.NET version: .NET 6
Browser: Chrome v 110.0.5481.100
browserArgs:"--start-maximized", "--disable-site-isolation-trials", "--disable-blink-features", "--disable-blink-features=AutomationControlled"

After running for about 15-20 minutes

image

c# code:
var roundsElem = (await gameFrame.EvaluateAsync(@"() => { return e_getRounds();}")).Value;
js code:
function e_getRounds() { return PlazaManager.getInstance().videosMaps.table; }
Injected code:
await frame.AddScriptTagAsync(new FrameAddScriptTagOptions { Content = ClientConsts.gameRPCScript });

The page is in the iframe, and the js code is injected by listening to the FrameNavigated event of the iframe. Everything is fine without calling ifame.EvaluateAsync, which is enabled every 3 seconds, increases the node memory footprint until a memory leak occurs.
Also tried using 1.28.0/1.29.0/1.30.0 and had the same problem.
How do I fix it?

@hanfeige
Copy link
Author

Context:

Playwright Version: 1.27.2 Operating System: Windows .NET version: .NET 6 Browser: Chrome v 110.0.5481.100 browserArgs:"--start-maximized", "--disable-site-isolation-trials", "--disable-blink-features", "--disable-blink-features=AutomationControlled"

After running for about 15-20 minutes

image

c# code: var roundsElem = (await gameFrame.EvaluateAsync(@"() => { return e_getRounds();}")).Value; js code: function e_getRounds() { return PlazaManager.getInstance().videosMaps.table; } Injected code: await frame.AddScriptTagAsync(new FrameAddScriptTagOptions { Content = ClientConsts.gameRPCScript });

The page is in the iframe, and the js code is injected by listening to the FrameNavigated event of the iframe. Everything is fine without calling ifame.EvaluateAsync, which is enabled every 3 seconds, increases the node memory footprint until a memory leak occurs. Also tried using 1.28.0/1.29.0/1.30.0 and had the same problem. How do I fix it?

@hanfeige
Copy link
Author

Context:
Playwright Version: 1.27.2 Operating System: Windows .NET version: .NET 6 Browser: Chrome v 110.0.5481.100 browserArgs:"--start-maximized", "--disable-site-isolation-trials", "--disable-blink-features", "--disable-blink-features=AutomationControlled"
After running for about 15-20 minutes
image
c# code: var roundsElem = (await gameFrame.EvaluateAsync(@"() => { return e_getRounds();}")).Value; js code: function e_getRounds() { return PlazaManager.getInstance().videosMaps.table; } Injected code: await frame.AddScriptTagAsync(new FrameAddScriptTagOptions { Content = ClientConsts.gameRPCScript });
The page is in the iframe, and the js code is injected by listening to the FrameNavigated event of the iframe. Everything is fine without calling ifame.EvaluateAsync, which is enabled every 3 seconds, increases the node memory footprint until a memory leak occurs. Also tried using 1.28.0/1.29.0/1.30.0 and had the same problem. How do I fix it?

After testing, I found that if the injection function method is not applicable, the amount of memory growth will be greatly reduced. That is, the js function is not injected in advance, but used directly at execution, such as:

Old Code:

frame.AddScriptTagAsync(new FrameAddScriptTagOptions { Content = "function e_getRounds() { return PlazaManager.getInstance().videosMaps.table; }" });
var roundsElem = (await gameFrame.EvaluateAsync(@"() => { return e_getRounds();}")).Value;

New Code
var roundsElem = (await gameFrame.EvaluateAsync(@"() => { return PlazaManager.getInstance().videosMaps.table;}")).Value;

But that still doesn't solve the memory leak problem, and memory continues to grow, from about 15 minutes to about 45 minutes.

@hanfeige hanfeige reopened this Feb 15, 2023
@mxschmitt
Copy link
Member

Can you provide us a repro which we can run locally?

@hanfeige
Copy link
Author

Can you provide us a repro which we can run locally?

After testing, it was found that the causes are as follows: When calling js to obtain the page data, need to minimize the content returned, I will need to return the data by reconstructing the object, only return a few fields, then can greatly reduce the memory, it is not clear what is the cause, tomorrow I upload a test code

@hanfeige
Copy link
Author

Can you provide us a repro which we can run locally?

https://github.com/hanfeige/JsStacktrace.git

@mxschmitt mxschmitt changed the title node memory leak [Bug] Memory leak when evaluating Mar 2, 2023
@mxschmitt mxschmitt transferred this issue from microsoft/playwright-dotnet Mar 2, 2023
@mxschmitt
Copy link
Member

I was able to track it down to this specific line:

_raceAgainstContextDestroyed<T>(promise: Promise<T>): Promise<T> {
return Promise.race([
this._destroyedPromise.then(e => { throw e; }),
promise,
]);
}

and this upstream issue: nodejs/node#17469

we'll implement a workaround accordingly.

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

Successfully merging a pull request may close this issue.

2 participants