-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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]: Selenium SessionNotCreatedException: "User data directory is already in use" when running as root #15327
Comments
@ammarft-ai, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
I am not sure how we can help. You need to make sure the profile is not being used. |
This could be caused by trying to access a profile that's already in use, or if the profile is not readable/writeable (yours seems to be owned by root?) Either way, the error message is coming from chromedriver, so I don't think there is anything to fix from the selenium side. |
It also occurs in my environment. OS:Windows10 |
I don't know the cause, but I avoided the error by running msedgedriver.exe before initializing the driver.
|
Try running However, since the error is coming from ChromeDriver... this doesn't look like a selenium issue and it should reported to the ChromeDriver devs. |
Why are you running as Admin? Also, the reported issue was for Chrome, not Edge. |
@cgoldberg The PC where the error occurred did not have administrator rights, but it did occur. And I was able to avoid the error with this method. Although it is a Chrome issue, I thought that a similar method could be used, so I left a comment. |
If running as admin (in Windows) or with sudo (in Linux), can you try to pass browser arg |
I can confirm this exact issue as well, both in Debian Bullseye running in docker container as well as in Ubuntu installed in WSL. selenium 4.29.0 installed in conda environment through pip. |
Can confirm this issue when running as a root user from an Ubuntu 24-based Docker container. This issue does not occur when running from a non-root user. |
I was able to reproduce this on Debian, but only running as root. I get the same exception reported in this issue when trying to instantiate The repro steps are simply:
Then run a Python script containing:
Here is a Python shell session showing all 3 failures:
Here is what happens when trying to just run Chrome as root:
Here is what happens when trying to run Chrome as root and including the
Here is what happens when trying to run Firefox as root:
I definitely have an X server running... and here is the contents of $DISPLAY:
So... I would say that this is not a bug in Selenium, ChromeDriver, EdgeDriver, or GeckoDriver. It is an issue with running Chrome/Edge/Firefox as root. I don't know the cause. Perhaps a bug in the browsers? Perhaps it's because root can't open an X display running as a regular user? Regardless, the real question is WHY do you need to run Selenium (and therefore the browser and driver) as root? I can't think of a valid use case for this... but maybe someone has one. |
I was having this error when trying to run the driver inside a Docker Container (python:3.10-slim). Adding the --user-data-dir as an argument solved the issue in this case.
|
@tianmrn95 @stanislaw @Venousek @thepbnk Interesting. Were you running as root or a regular user in the container when getting the error? To decouple this from selenium, can you run chrome directly inside your container (just start the browser from the command line without selenium)? Verify it doesn't work, then add the With that information, someone can submit a bug to Chrome/Edge and see what they say about running the browser as root. I guess this the use case I was looking for. Docker containers run as UID 0 (root) by default. That seems like bad practice, but I guess it's common... so that makes it a valid use case for running selenium as an elevated/root user. |
I'm having this same issue. Running in a docker container tried combinations of
Running chromedriver directly in the container via docker exec works just fine:
|
I don't think executing chromedriver alone would reproduce this, because it's just waiting for a command to launch chrome, and that is when the issue occurs. Can you try launching chrome directly (not chromedriver) inside your container , both with and without the |
Thank you for the for the suggestion!! Apparently there are quite a few libraries required by Chrome that must be installed in the python docker images. Once installed it all works. Below is the first part of the dockerfile I used that pulls the latest stable chrome and chromedriver, and install the required libraries. Just a suggestion -- if chrome fails to start, a more appropriate error message would save a ton of time.
|
So your issue was just that you didn't have the necessary dependencies in your container to run chrome? That seems totally unrelated to the issue being discussed here (although you probably saw a similar error message). Unfortunately, Selenium can only provide whatever error message ChromeDriver returns when Chrome doesn't start. FWIW, you don't need to download and install Chrome/ChromeDriver like you are doing. It is done automatically through Selenium Manager. |
@cgoldberg Indeed, my Docker container is running with root privileges. After some debugging, I found that adding --user-data-dir was not the solution in my case, but using --no-sandbox was. My issue seems to be related to running Chrome as root without the --no-sandbox option (see this issue). When trying to run the Chrome command: As non-root:
As root:
It looks like this issue is already being discussed here: https://issues.chromium.org/issues/373753919. |
For me, changing from the |
…er user This done to implement the following constraints: 1) The Docker container runs a non-root user because otherwise Chrome/ChromeDriver are not happy as per this issue: SeleniumHQ/selenium#15327 2) StrictDoc runs within a container and outputs artifacts that have the UID/GID of the host user. The approaches that I could not make work: 1) Running with a default root user because of the permissions issue and Chrome raising an error about the environment. 2) Using `USER` inside the container and then running an image with `--user $(id -u):$(id -g)`. With this approach, the Chrome would not be happy because the container will be running from a user that does not have a proper home directory. Maybe there are better solutions but the one with the entrypoint.sh seems to be good enough.
I am getting this error too. But I haven't changed any code or anything. I'm not running on docker. I even created a test.py file with bare minimum code with a single driver instance and I still get the same error? Did something change with selenium or the driver? For reference, the script I wrote was multiprocessed selenium that scraped and worked fine for months, profiles were assigned based on the id given from the multiprocessing module. I am using webdriver_manager. But I also used conda to create a new environment with selenium today. Either the new environment, the new webdriver, or the new selenium is the problem here. |
test code for reference after I tried a downloaded recent edgedriver to test.
selenium version: 4.29.0 |
Found a fix in another issue. add "--edge-skip-compat-layer-relaunch" to options. |
@thos-grol |
I'm running into the same issue. Just spun up a DigitalOcean droplet. Ran the following after server loaded (ubuntu 22.04.5 LTS)
Installed the libraries from pip. Then ran the following.
Same with something simple.
Error
pip freeze
lsb_release -a
|
@niceguy4 |
I didn't download chromedriver for this round of testing. I thought Selenium handles the download? my /usr/bin/ directory does not have chrome or chromedriver |
@niceguy4 |
@cgoldberg chrome 134.0.6998.35
When I try to do ./chrome --version i get this. Not sure if it means anything.
It looks like when I manually load the driver there is no issue but I'm not exactly sure what I'm doing, lol.
Ran this for the missing chrome item. I now get this when I do ./chrome --version
|
@niceguy4 |
|
@niceguy4 actually... I see you are running as root... so chrome is going to fail, and that is the cause of this issue. See my comment earlier in this thread where I showed that was happening. I would recommend not running as root to get around this. |
@niceguy4 |
@cgoldberg Interesting. Love root and accidentally deleting my server sometimes :) Here's with a user instead of root.
|
@niceguy4 p.s. don't run as root, like ever. Use sudo if you need temporary privileges :) |
@cgoldberg Shit. It works now and I have no idea why it works. "It", being this script.
Would it be helpful to spin up another Digitalocean box and see if the issue is running python as root? Also, I did run this a couple comments up so it might be related to this command below. |
I'd run
root :) |
@niceguy4 |
@caborabo thank you for your help. Really sorry for wasting your time. |
@cgoldberg I spun up another ubuntu DO droplet. It appears that this item below "fixed" the issue. I ran everything as root user, too but will not run as root going forward :)
My full steps for the DO ubuntu server.
For this code...
No issues.
edit: this is only true for ubuntu 22.04. Steps above work for ubuntu 22.04. None of the steps above worked for ubuntu 24.10, running as non-root user and installing the apts listed above. Still have the same issue for ubuntu 24.10 edit3: I'm going nuts, my brain is melting. It appears that |
@niceguy4 |
@niceguy4, I saw your comment mentioned the issue when you ran test in the container, and fix by installing missing deps via |
Same issue but it occurred when upgrading from 131 to upper version With the same parameters to launch cromedriver. |
You'll have to take that up with chrome/chromedriver maintainers. |
I was using admin. But with that option it now works even though I am using it. |
@VietND96 Thank you! |
If you are using ubuntu bash, u have to run this commend before runing a selenium program |
What happened?
I am trying to launch a headless Chrome WebDriver using Selenium in Python. However, I keep encountering this error:
How can we reproduce the issue?
Relevant log output
Operating System
Ubuntu
Selenium version
4.29.0
What are the browser(s) and version(s) where you see this issue?
Chrome
What are the browser driver(s) and version(s) where you see this issue?
Google Chrome 133.0.6943.126 ChromeDriver stable(auto)
Are you using Selenium Grid?
No response
The text was updated successfully, but these errors were encountered: