playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
2.11k stars 156 forks source link

Playwright-go silently hanging at random points #390

Open achsal2 opened 10 months ago

achsal2 commented 10 months ago

i saw a similar issue on this but it was said that its been fixed yet i still face this issue where sometimes the browser just hangs and becomes unresponsive to any calls at random points of my scraper after a while, it doesnt crash or disconnect, just goes unresponsive, it's a hard issue to reproduce because it happens randomly and i tested every single action to make sure where the specific call that causes this can be but its random, i have 5 workers each processing some jobs that call newContext and newPage and execute the process then clean up by closing the page and context, on playwright's issues i heard not using the same context over and over is good to avoid this but could this be whats causing it ?

canstand commented 10 months ago

try run in debug mode in vscode, and pause the execution when a hang occurs, then check the call stack of the racing goroutine

achsal2 commented 10 months ago

its very hard for me to debug on vscode since this happens one after a while of processing a large number of data , but i did notice that when i switch off a handler that deals with iframes i have yet to see it freeze then, and i also remember being on go-rod and the browser would crash everytime it needed to work with an iframe and it wasnt headless so im tempted to say its relating to working with elements inside iframes. the go-rod developers said its potentially a bug with chrome devtools is there a know issue with iframes in playwright as well ?

i know its hard to work with a bug that cant be consistantly reproduced so thanks for the help im trying to figure out how i can reproduce it

achsal2 commented 10 months ago

for anyone facing the same issue, its due to the use of .Lock and .Unlock all over the playwright library which creates deadlocks , in my case it was a race condition between the router handling or waiting for a request to finish (due to route.Fetch probably) and a call to page.Close(), the only way i got it to work is by removing playwright's p.Lock() and p.Unlock() and adding my own graceful shutdown logic for the router, aborting the requests before calling page.Close()

im not aware if there's a workaround to this without modifying playwright so if you do let me know

canstand commented 6 months ago

The latest version should have some improvements. But it is known that firefox may still have problems.

https://github.com/playwright-community/playwright-go/issues/362#issuecomment-1976673567