Repository navigation
Description
Description
When several Selenium Manager processes share a cache, one of them can get a browser path back while another process is still copying that browser into the cache. The browser then fails to start. With Chrome, chromedriver reports session not created: Chrome instance exited.
The cache lock added for #13511 and #13686 stops two processes from downloading at the same time. However, download_browser checks whether the browser binary exists before it takes the lock (rust/src/lib.rs:323). If the binary is there, it returns that path without waiting on the lock. The process doing the download holds the lock while it unzips into a temporary folder and then copies the files into the cache one at a time (copy_folder_content). The binary can be copied before the libraries and resources it needs. Any process that checks during that copy gets a path to an incomplete browser.
The driver has the same unlocked check (rust/src/lib.rs:969). The window there is smaller, since only a single file is copied.
This affects every binding, and any process that shares a cache folder: parallel test workers in one CI job, or several runners on one self-hosted machine.
Expected: a browser path is returned only once that browser is fully in the cache.
Possible fixes:
- Unzip into a temporary folder inside the cache and rename it into place once complete. Alternatively, write a marker file last and check for the marker instead of the binary.
- Check for the binary only after taking the lock. This is simpler, but every run then waits on the lock.
Reproducible Code
# Watches the cache while one process downloads Chrome for Testing.
# The browser binary appears long before the rest of the files.
SM=/path/to/selenium-manager
CACHE=$(mktemp -d)
"$SM" --browser chrome --browser-version 157 --force-browser-download \
--cache-path "$CACHE" --output json > /dev/null 2>&1 &
PID=$!
while kill -0 $PID 2>/dev/null; do
files=$(find "$CACHE/chrome" -type f 2>/dev/null | wc -l | tr -d ' ')
binary=$(find "$CACHE/chrome" -type f \( -path '*MacOS/Google Chrome for Testing' -o -name chrome \) 2>/dev/null | wc -l | tr -d ' ')
echo "files=$files binary=$binary"
sleep 0.05
done | uniq
# Running a second selenium-manager with the same arguments while the
# output shows binary=1 and an incomplete file count makes it log
# "chrome ... already exists at ..." and return the incomplete browser.Debugging Logs
# macOS arm64, Selenium Manager from selenium-webdriver 4.53.0
files=0 binary=0
files=1 binary=0
files=37 binary=1
files=349 binary=1
At the files=37 binary=1 step, any other Selenium Manager process gets this browser back from the unlocked check, even though only 36 of its 349 files are in place (the other file is the lock).
Activity