-
-
Notifications
You must be signed in to change notification settings - Fork 170
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 in node process #520
Comments
me too |
Please log if there is an error when closing BrowserContext. defer func() {
err := context.Close()
if err != nil {
log.Printf("Failed to close browser context: %v", err)
}
}() |
@canstand, thank you for your suggestion!
I modified my code to log any errors when closing the context as you recommended. However, after running the program with this change, no errors are being logged when closing the context. The memory consumption of the node process continues to increase over time. I also tried adding Updated method: func (ps *PlaywrightService) OpenURL(url string) error {
context, err := ps.BrowserInstance.NewContext()
if err != nil {
return fmt.Errorf("creating browser context: %v", err)
}
defer func() {
err := context.Close()
if err != nil {
log.Printf("Failed to close browser context: %v", err)
} else {
log.Println("Browser context successfully closed")
}
}()
page, err := context.NewPage()
if err != nil {
return fmt.Errorf("creating new page: %v", err)
}
defer func() {
err := page.Close()
if err != nil {
log.Printf("Failed to close page: %v", err)
} else {
log.Println("Page successfully closed")
}
}()
if _, err := page.Goto(url, playwright.PageGotoOptions{
Timeout: playwright.Float(5000),
}); err != nil {
return fmt.Errorf("navigating to %s: %v", url, err)
}
return nil
} Output: |
Page takes too many memory, You do not need to close the browser, use only one browser, make sure to close the page, and increase access step by step. |
I think you are from China or Asia. |
@wade-liwei, |
I am an English beginner, |
why do you need different browser context for each request? |
I think we might be experiencing the same issue, as I'm observing the same increase in memory usage as shown in your screenshot from your issue (#525).
I need to create a new browser context for each request to ensure that cookies and localStorage are isolated. This isolation is crucial to prevent shared state between requests. As I mentioned earlier, I'm closing both the page and the browser context using defer |
got it. Your problem may be Golang GC, do you use docker to limit memory resources? and headless use less memory. |
Environments
Bug description
When running my program that uses playwright-go for an extended period, the node process starts consuming more and more RAM.
An hour after launching my program, the node process consumes the following amount of memory:
![Image](https://private-user-images.githubusercontent.com/59907691/405173512-2053b785-5468-4546-ac0f-5669a5f88b16.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMjEyMjMsIm5iZiI6MTczOTMyMDkyMywicGF0aCI6Ii81OTkwNzY5MS80MDUxNzM1MTItMjA1M2I3ODUtNTQ2OC00NTQ2LWFjMGYtNTY2OWE1Zjg4YjE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDAwNDIwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJlYzlhMDlmM2RlYjEyMWY1NGRiMWRkZjczNzM5YWQwMjUzMmM0NjQ0NDMyZTdjZmYwNDc4NzJkYzNlMTI0NWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.OBs9UU0n2YWZj2g3LU7_CGB8kqUUO-2dOAlhA1tYnoo)
After 4 days of continuous operation, the memory consumption increases:
![Image](https://private-user-images.githubusercontent.com/59907691/405173513-5118ea7a-cc84-489c-a039-98889cc3d3d2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzMjEyMjMsIm5iZiI6MTczOTMyMDkyMywicGF0aCI6Ii81OTkwNzY5MS80MDUxNzM1MTMtNTExOGVhN2EtY2M4NC00ODljLWEwMzktOTg4ODljYzNkM2QyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDAwNDIwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQyNzhiMTczMDI1YmQ1MWM4YmEwNjZkNzhlMDQ5NTMzNDRhODg4MzIxNGM0YzRjMzNiOTJjZWU5ZWNjYjIyYjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.CPMn5-iY019019a8ytRjYFUXuhlAl3ZIr_pjnnHlBlU)
Based on the RSS field, after one hour of running the program, the node process was consuming approximately 73 MB of memory (RSS: 75,244 KB). After 4 days of operation, it increased to approximately 296 MB (RSS: 302,844 KB).
This indicates a steady increase in memory usage by the node process, which may suggest a memory leak.
To Reproduce
Please consider the minimal code example that demonstrates the issue:
Additional context
In this code, the program continuously opens the specified URL in an infinite loop with a 10-second interval. Each cycle creates a new browser context and a new page, which are then closed using defer. Despite this, there is a constant increase in memory consumption by the node process. This may indicate a possible memory leak in playwright-go or an issue in the interaction with Node.js.
I would appreciate any help in resolving this problem.
The text was updated successfully, but these errors were encountered: