If you start two instances of chrome against the same user-data-dir, then the second instance will simply print "Created new window in existing browser session." and exit.
There is a race condition here where if two ChromeDriver instances (instance A and instance B) are started against the same user-data-dir then the following could happen:
- instance A checks for a already existing DevToolsActivePort file and deletes it if it exists.
- instance B checks for a already existing DevToolsActivePort file and deletes it if it exists.
- instance A starts Chrome at the given user-data-dir. Chrome writes the DevToolsActivePort file to that directory. instance A connects to devtools at the port given by the DevToolsActivePort file.
- instance B starts Chrome at the given user-data-dir, but Chrome simply prints "Created new window in existing browser session." and exits. At this point, instance B should exit saying that it failed to start Chrome, but instead it continues forward, reads the DevToolsActivePort file, and connects to DevTools about that given port.
Now we have two ChromeDriver instances connecting to the same Chrome!
Note that there are two reasons that this "bug" isn't very important:
1. User should not give us the same user-data-dir for two different Chrome runs. There's no way for us to handle this scenario anyway.
2. Usually the order of operations above is not the way that this works. Usually instance B deletes the DevToolsActivePort file created by instance A and then instance B times out waiting for a new DevToolsActivePort file to be created.
3. Usually no user-data-dir is provided by the user anyway, and ChromeDriver uses CreateUniqueTempDir https://cs.chromium.org/chromium/src/base/files/scoped_temp_dir.h?g=0&l=36 to create a new randomly-named temporary directory, so no collision or race condition is possible.
The solution to this problem is for ChromeDriver to handle the "Created new window in existing browser session." case and throw a helpful error for it. I'm not really sure why the current code doesn't handle this case already, so we will need to look into it.
Comment 1 by crouleau@chromium.org
, Oct 2