Skip to content
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]: C#: Driver process left running if DriverService is reused and Driver disposed #14624

Open
kevinoid opened this issue Oct 19, 2024 · 9 comments · May be fixed by #14662
Open

[🐛 Bug]: C#: Driver process left running if DriverService is reused and Driver disposed #14624

kevinoid opened this issue Oct 19, 2024 · 9 comments · May be fixed by #14662

Comments

@kevinoid
Copy link

kevinoid commented Oct 19, 2024

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?

var driverService = ChromeDriverService.CreateDefaultService();
var driver1 = new ChromeDriver(driverService);
driver1.Dispose();
var driver2 = new ChromeDriver(driverService);
driver2.Dispose();

Relevant log output

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: <null>, 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: <null>, 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

Copy link

@kevinoid, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@kevinoid
Copy link
Author

If it is incorrect to reuse an instance of DriverService, perhaps it would make sense for the Driver constructor to throw, or for DriverService to throw instead of starting a new driver service process from a disposed instance?

@nvborisenko
Copy link
Member

How I am reading it:

var driverService = ChromeDriverService.CreateDefaultService(); // just new driverService object
var driver1 = new ChromeDriver(driverService); 
driver1.Dispose(); // you dispose driver1 but not driverService 
var driver2 = new ChromeDriver(driverService);
driver2.Dispose(); // you dispose driver2 but not driverService 

So, driverService should not be disposed! And it is correct behavior.

@kevinoid
Copy link
Author

So, driverService should not be disposed! And it is correct behavior.

Are you saying it is a bug that driverService is disposed by driver1.Dispose()? For reference, this occurs in WebDriver.Dispose(), which calls DriverServiceCommandExecutor.Dispose():

this.executor.Dispose();
which calls DriverService.Dispose():

@nvborisenko
Copy link
Member

How it works currently:

var driverService = ChromeDriverService.CreateDefaultService();
var driver1 = new ChromeDriver(driverService); // starts new chromedriver.exe
driver1.Dispose(); // ends the chromedriver.exe
var driver2 = new ChromeDriver(driverService); // starts new chromedriver.exe
driver2.Dispose(); // DOES NOT end the chromedriver.exe

This is definitely a bug, user experience should be improved here. I don't know whether ChromeDriverService is supposed to be reusable: understanding it let's us understand what is expected user experience should be.

@diemol @titusfortner do you know whether ChromeDriverService is considered as reusable object, comparing with other bindings?

@nvborisenko
Copy link
Member

@kevinoid did it work properly with previous Selenium version, and which one?

@kevinoid
Copy link
Author

did it work properly with previous Selenium version, and which one?

@nvborisenko Testing just now, I'm able to reproduce the issue with Selenium.WebDriver versions back to 3.11.1, but I'm unable to reproduce the issue with 3.11.0 or earlier.

@nvborisenko
Copy link
Member

Thank you good man, it will help so much!

@nvborisenko
Copy link
Member

Current understanding is: ChromeDriverService should be reusable.

@nvborisenko nvborisenko linked a pull request Oct 27, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants