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

Temporary Files #1079

Closed
jschlade opened this issue Sep 24, 2022 · 19 comments
Closed

Temporary Files #1079

jschlade opened this issue Sep 24, 2022 · 19 comments

Comments

@jschlade
Copy link

Using Playwright 1.25 for java on Windows with the Firefox driver.
Using a 1.8 JVM

Seeing lots of temp files leftover:
temp_file_dir

Why?
And is there a way to delete them before my Playwright application ends?

Thanks

@mxschmitt mxschmitt transferred this issue from microsoft/playwright Sep 26, 2022
@yury-s
Copy link
Member

yury-s commented Sep 26, 2022

Playwright Java consists of two parts: java client that provides all the APIs and a driver which is shared between all language ports. The driver is a node.js application which is archived in a maven package and is extracted into a temp directory every time you launch playwright. The directory is automatically deleted after the application finishes. You cannot delete it before you finished running playwright as it will break it.

@yury-s yury-s closed this as completed Sep 26, 2022
@jschlade
Copy link
Author

Hi @yury-s - This is a bug then as I don't see this getting cleaned up. Is there a way to debug this? Thanks

@yury-s
Copy link
Member

yury-s commented Sep 26, 2022

The files/dirs are marked as deleteOnExit() so if JVM exits without errors the should be removed.

@jschlade
Copy link
Author

They aren't. I have a long running program that's doing multiple searches over many hours and I see left over files like this so for some reason playwright didn't delete the dir containing the node.exe file when it started at 8:13 am and I exited in around 2:30 pm today.

@yury-s - Please help me debug this. Why is this happening?

Thanks

image

@yury-s yury-s reopened this Sep 27, 2022
@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

It may happen if node.exe didn't exit properly and still holding some of the files. Can you check for remaining node processes after the app exits? Usually Playwright will kill them before exit if the are not responsive but maybe there is a bug.

Also, does it happen with a simple scenario that just runs a test and exits? Having a reproducible example would be helpful.

@jschlade
Copy link
Author

I don't see that node.exe is still running?
But I see this message all the time:

INFO: Closing client connection.
The batch file cannot be found.

  • What batch file is it looking for?
  • Is this doing the deleting?
  • Any other debugging I can enable?

image

Thanks

@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

Try running with DEBUG=pw:browser,pw:install env variable, it will enable extra logging that may shed some light on what's going on.

INFO: Closing client connection.
The batch file cannot be found.

This may be printed if the batch file that we use to launch node is missing, e.g. it was deleted from the temp directory already.

@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

INFO: Closing client connection.
The batch file cannot be found.

This may be printed if the batch file that we use to launch node is missing, e.g. it was deleted from the temp directory already.

This is where we construct the file name. You can pause in the debugger there, and check if playwright.cmd is actually present at that path.

@jschlade
Copy link
Author

INFO: Closing client connection.
2022-09-27T17:42:33.165Z pw:browser [pid=28088]
2022-09-27T17:42:33.465Z pw:browser [pid=28088]
2022-09-27T17:42:33.466Z pw:browser [pid=28088] starting temporary directories cleanup
2022-09-27T17:42:33.500Z pw:browser [pid=28088] finished temporary directories cleanup
2022-09-27T17:42:33.500Z pw:browser [pid=28088]
The batch file cannot be found.

image

Still seeing leftover directories:

  • mozilla-temp-files has nothing in it.
  • playwright-java-7998165960572586948 has node.exe in it.

Thanks

@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

  • mozilla-temp-files has nothing in it.

This might be created by firefox, playwright itself doesn't create such folder as far as I know.

  • playwright-java-7998165960572586948 has node.exe in it.

It means that the node process is still hanging around preventing the directory from being deleted. You should be able to find it in the task manager.

The batch file cannot be found.

I cannot make sense of it, it looks like you are trying to launch playwright again after the cleanup started. Can it be that there is a periodic job that does temp folder cleanup and interferes with the running Playwright instance?

@jschlade
Copy link
Author

Okay so there it is running:

image

I see this:

2022-09-27T18:20:39.625Z pw:install created DriverJar: C:\Users\xxxx\AppData\Local\Temp\playwright-java-7557468934805508290
2022-09-27T18:20:39.627Z pw:install initializing driver
2022-09-27T18:20:40.068Z pw:install extracted driver from jar to C:\Users\xxxx\AppData\Local\Temp\playwright-java-7557468934805508290\playwright.cmd
2022-09-27T18:20:41.750Z pw:install Chromium 105.0.5195.19 (playwright build v1019) is already downloaded.
2022-09-27T18:20:41.750Z pw:install FFMPEG playwright build v1007 is already downloaded.
2022-09-27T18:20:41.751Z pw:install Firefox 103.0 (playwright build v1344) is already downloaded.
2022-09-27T18:20:41.751Z pw:install Webkit 16.0 (playwright build v1699) is already downloaded.
2022-09-27T18:20:41.760Z pw:install driver initialized.
2022-09-27T18:20:42.212Z pw:browser C:\Users\xxxx\AppData\Local\ms-playwright\firefox-1344\firefox\firefox.exe -no-remote -headless -profile C:\Users\xxxxx\AppData\Local\Temp\playwright_firefoxdev_profile-bFSqGD -juggler-pipe -silent
2022-09-27T18:20:42.214Z pw:browser pid=8080
2022-09-27T18:20:42.245Z pw:browser [pid=8080][err] *** You are running in headless mode.
2022-09-27T18:20:42.495Z pw:browser [pid=8080][out]
2022-09-27T18:20:42.495Z pw:browser [pid=8080][out] Juggler listening to the pipe

Then when I quit my application:

INFO: Closing client connection.
2022-09-27T18:33:06.975Z pw:browser [pid=8080]
2022-09-27T18:33:07.103Z pw:browser [pid=8080]
2022-09-27T18:33:07.103Z pw:browser [pid=8080] starting temporary directories cleanup
2022-09-27T18:33:07.139Z pw:browser [pid=8080] finished temporary directories cleanup
2022-09-27T18:33:07.139Z pw:browser [pid=8080]
The batch file cannot be found.

No node.exe:

image

And the folder is still there:

image

There isn't anything deleting directories, etc. from my %temp% directory.
Why is it trying to run this .cmd file when the program is exiting after the cleanup? That doesn't make sense.

@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

Why is it trying to run this .cmd file when the program is exiting after the cleanup? That doesn't make sense.

I have no explanation for that, it should not. Perhaps it's the same code that prints "INFO: Closing client connection." (Playwright doesn't have such messages). Would you be able to share minimal reproducible example?

@jschlade
Copy link
Author

INFO: Closing client connection. - Is my code.
My app logs into a financial website so I'm not sure it would be easy to reduce it into something non proprietary.

Based on what I've seen it seems like there are a few issues here. Can you give me another build that has more debugging capabilities?

Thanks

@yury-s
Copy link
Member

yury-s commented Sep 27, 2022

Based on what I've seen it seems like there are a few issues here. Can you give me another build that has more debugging capabilities?

I could but I'm not sure where to put that logging. It seems that the problem is somewhere in the implementation of the deleteOnExit() method + how the node instances are shutdown. Can you check if it's reproducible it with a simple example, like one of those we have in the examples directory?

Which JVM do you use?

@yury-s
Copy link
Member

yury-s commented Oct 5, 2022

We need more information to act on this report. Please file a new one and link to this issue when you get back to it!

@yury-s yury-s closed this as completed Oct 5, 2022
@pete89-p
Copy link

Hey. I'm seeing the same issue with temp files. 'The batch file cannot be found.'
Playwright version: 1.36.0
Java: 21
image
I'm closing the context first, then the browser.
Is there a solution for this?

@NIKOLENKO-TE
Copy link

NIKOLENKO-TE commented Mar 12, 2024

@yury-s
The batch file cannot be found.
Same problem. I tried different versions of everything possible.
I created the simplest test project. After every test I see this error.
After each test, the temporary folder is not deleted. The file node.exe remains in it.
The playwright.cmd file remains if the test is interrupted. Does this error occur because the node.exe process is still busy when the test completes and it cannot delete the temporary folder?
Gradle: 8.4, 8.5, 8.6;
Playwright: 1.41.2;
Java: 11, 17, 18, 21;
I added my own variable Windows but it didn't help.

Screenshot 2024-03-12 230904
Screenshot 2024-03-12 231039
Screenshot 2024-03-12 231131
Screenshot 2024-03-12 231345
Screenshot 2024-03-12 231841
Screenshot 2024-03-12 232351
Screenshot 2024-03-12 233837

In my other project where there are only 20 tests, this error is duplicated 5 times.

Screenshot 2024-03-12 234538

@rojashr
Copy link

rojashr commented Apr 16, 2024

Hello @yury-s I hope you are well, is there a reason this issue was closed?

I can reproduce this consistently on my local setup and in a remote server, I am using Java 11 and 17 and Playwright version 1.37.0.

The description provided by @NIKOLENKO-TE above is quite thorough about the problem, do you need more information from our side?

@yury-s
Copy link
Member

yury-s commented Apr 16, 2024

Please don't comment on the closed issues, we don't monitor them. This one was closed because we were not able to reproduce it and hence could not take any action on it. If you have a good repro, feel free to open a new bug and provide the steps there.

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

5 participants