microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.68k stars 3.58k forks source link

[Bug]: Jobs running concurrently on the same machine download browsers to the same directory and clobber each other (Windows) #32179

Open rjpowers10 opened 1 month ago

rjpowers10 commented 1 month ago

Version

1.44

Steps to reproduce

I'm using Azure DevOps Server with self-hosted agents (Windows). I am running many pipelines throughout the night and part of that is running Playwright tests (.NET and MSTest).

Each agent installs the browsers to an agent-specific directory using the PLAYWRIGHT_BROWSERS_PATH environment variable. This way each agent has its own copy of the browsers and everything is nicely isolated.

The issue is that while the browsers are eventually installed to PLAYWRIGHT_BROWSERS_PATH, they are downloaded to C:\Users\username\AppData\Local\Temp. While I have multiple agents, several of them are running on the same machine as the same user. This means that if agent 1 and agent 2 are running at roughly the same time, they will both try to download the browsers to the same location and will end up clobbering each other.

Expected behavior

The PLAYWRIGHT_BROWSERS_PATH keeps the browsers completely isolated, including the download.

Actual behavior

The agent will begin to download the browsers but it won't be long before you see this error.

[Error: ENOENT: no such file or directory, open 'C:\Users\[REDACTED]\AppData\Local\Temp\playwright-download-firefox-win64-1449.zip'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\[REDACTED]\\AppData\\Local\\Temp\\playwright-download-firefox-win64-1449.zip'
}

Additional context

No response

Environment

- Operating System: Windows Server 2022 21H2 (OS Build 20348.2655)
- Browser: All
- .NET Version (TFM): net8.0
- Other info: Azure DevOps Server 2022
rjpowers10 commented 1 month ago

The obvious workaround is to run the agents as separate users, and maybe that ends up being the final solution. But I figured I would at least raise the issue to gather thoughts about how PLAYWRIGHT_BROWSERS_PATH is supposed to behave and if it is reasonable for that to affect the download location as well.

pavelfeldman commented 1 month ago

Sounds like an easy fix, I can see

const zipPath = path.join(os.tmpdir(), downloadFileName);

in browserFetcher.ts