SeleniumHQ / SeleniumHQ/selenium
[🐛 Bug]: C#: Driver process left running if DriverService is reused and Driver disposed
- Dominant language
- Java
- Stars
- 34.5k
- Forks
- 8.7k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 92
Description
### What happened?
Using the same instance of `ChromeDriverService` to construct a second `ChromeDriver` instance after a first has been disposed causes a `chromedriver.exe` process to remain running after the program exits. The same issue occurs for `EdgeDriverService`/`EdgeDriver` (and presumably others, although I haven't tested).
### How can we reproduce the issue?
```csharp
var driverService = ChromeDriverService.CreateDefaultService();
var driver1 = new ChromeDriver(driverService);
driver1.Dispose();
var driver2 = new ChromeDriver(driverService);
driver2.Dispose();
```
### Relevant log output
```shell
18:12:02.680 TRACE SeleniumManager: Driver path: C:\Users\Kevin\.cache\selenium\chromedriver\win64\130.0.6723.58\chromedriver.exe
18:12:02.684 TRACE SeleniumManager: Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe
Starting ChromeDriver 130.0.6723.58 (3a50e012e4c9b8a410a4e2b12bf577e69ee8f755-refs/branch-heads/6723@{#1353}) on port 56805
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully on port 56805.
18:12:03.024 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"binary":"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"}}]}}
18:12:03.049 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:56805/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
Accept: application/json; charset=utf-8
User-Agent: selenium/4.25.0
User-Agent: (.net windows)
Content-Type: application/json; charset=utf-8
}
{"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"binary":"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"}}]}}
DevTools listening on ws://127.0.0.1:56808/devtools/browser/69268b21-d6f4-4d17-adc8-0bb82d03c81f
18:12:09.128 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Content-Length: 880
Content-Type: application/json; charset=utf-8
}
18:12:09.229 DEBUG HttpCommandExecutor: Response: (18ded7c147cc833ccfa3021204277f05 Success: System.Collections.Generic.Dictionary`2[System.String,System.Object])
18:12:09.673 DEBUG HttpCommandExecutor: Executing command: [18ded7c147cc833ccfa3021204277f05]: quit {}
18:12:09.768 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:56805/session/18ded7c147cc833ccfa3021204277f05', Version: 1.1, Content: , Headers:
{
User-Agent: selenium/4.25.0
User-Agent: (.net windows)
Accept: application/json
Accept: image/png
}
18:12:12.719 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Content-Length: 14
Content-Type: application/json; charset=utf-8
}
18:12:12.720 DEBUG HttpCommandExecutor: Response: ( Success: )
Starting ChromeDriver 130.0.6723.58 (3a50e012e4c9b8a410a4e2b12bf577e69ee8f755-refs/branch-heads/6723@{#1353}) on port 56805
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully on port 56805.
18:12:14.313 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{}}]}}
18:12:14.322 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:56805/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
Accept: application/json; charset=utf-8
User-Agent: selenium/4.25.0
User-Agent: (.net windows)
Content-Type: application/json; charset=utf-8
}
{"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{}}]}}
DevTools listening on ws://127.0.0.1:56818/devtools/browser/c557c74a-4deb-4032-af34-de1cb7df9c9f
18:12:17.843 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Content-Length: 882
Content-Type: application/json; charset=utf-8
}
18:12:17.864 DEBUG HttpCommandExecutor: Response: (fbc0e9deb4d2f1929299573b6f0c8826 Success: System.Collections.Generic.Dictionary`2[System.String,System.Object])
18:12:18.098 DEBUG HttpCommandExecutor: Executing command: [fbc0e9deb4d2f1929299573b6f0c8826]: quit {}
18:12:18.147 TRACE HttpCommandExecutor: >> Method: DELETE, RequestUri: 'http://localhost:56805/session/fbc0e9deb4d2f1929299573b6f0c8826', Version: 1.1, Content: , Headers:
{
User-Agent: selenium/4.25.0
User-Agent: (.net windows)
Accept: application/json
Accept: image/png
}
18:12:21.467 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache
Content-Length: 14
Content-Type: application/json; charset=utf-8
}
18:12:21.468 DEBUG HttpCommandExecutor: Response: ( Success: )
```
### Operating System
Windows 10
### Selenium version
C# with Selenium.WebDriver 4.25.0
### What are the browser(s) and version(s) where you see this issue?
Chrome 130.0.6723.59
### What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 130.0.6723.58
### Are you using Selenium Grid?
No
Contributor guide
Assessment
This issue has not been assessed yet.