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

[grid] ensure all states of StartOrDie are handled #11297

Merged
merged 1 commit into from Dec 5, 2022

Conversation

joerg1985
Copy link
Member

Description

DriverService.start did not fail, if the execution of the driver process was never started or the process did not bind the port.
In this case the status was PROCESS_IS_ACTIVE and the execution continued, trying to connect to the not bound port. Now there are meaningful exceptions raised to indicate the issue either "Timed out waiting for driver process to start." or "Timed out waiting for driver server to bind the port."

Motivation and Context

I had some driver/browser startup error with a SessionNotCreatedException caused by a ConnectionException, without a helpful message.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov-commenter
Copy link

Codecov Report

Base: 52.69% // Head: 52.69% // No change to project coverage 👍

Coverage data is based on head (fe02fa4) compared to base (c3f832b).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #11297   +/-   ##
=======================================
  Coverage   52.69%   52.69%           
=======================================
  Files          82       82           
  Lines        5545     5545           
  Branches      198      198           
=======================================
  Hits         2922     2922           
  Misses       2425     2425           
  Partials      198      198           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@joerg1985
Copy link
Member Author

This is the exception i saw before this patch:

rg.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: java.net.ConnectException: Connection refused: no further information: localhost/[0:0:0:0:0:0:0:1]:53835 
Host info: host: 'myHost', ip: 'x.x.x.x'
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.3'
Driver info: driver.version: unknown
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.4.1'
Driver info: com.daimler.protics.ta.driver.factory.SeleniumDrivers$2
Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: false, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {args: [-headless], prefs: {dom.ipc.processCount: 1, layers.acceleration.disabled: true, moz:debuggerAddress: true, security.enterprise_roots.enabled: true}}, unhandledPromptBehavior: ignore}], desiredCapabilities=Capabilities {acceptInsecureCerts: false, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {args: [-headless], prefs: {dom.ipc.processCount: 1, layers.acceleration.disabled: true, moz:debuggerAddress: true, security.enterprise_roots.enabled: true}}, unhandledPromptBehavior: ignore}}]
Capabilities {}
	org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:144)
	org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:102)
	org.openqa.selenium.remote.ProtocolHandshake.createSession (ProtocolHandshake.java:67)
	org.openqa.selenium.remote.HttpCommandExecutor.execute (HttpCommandExecutor.java:156)
	... more

@joerg1985
Copy link
Member Author

joerg1985 commented Nov 23, 2022

Here is some code to provoke the DriverService.start will not wait for the port to be opened in some situations:

public static void main(String[] args) throws IOException {

        // notepad.exe will start but not bind the port
        while (true) {
            DriverService service = new DriverService(
                    new File("C:\\Windows\\notepad.exe"), 54001, Duration.ofSeconds(4), Collections.emptyList(), Collections.emptyMap()
            ) {

            };

            try {
                service.start();
            
                throw new IllegalStateException("should never be reached or did notepad open the port?");
            } catch (org.openqa.selenium.WebDriverException e) {
                //swallow the expected issue
                LOG.info("got the expected WebDriverException: " + e.getMessage());
                continue;
            }
        }
    }

Log output (the number of spins it takes to fail varies for each run):

Nov. 23, 2022 4:56:47 PM Main main
INFORMATION: got the expected WebDriverException: Timed out waiting for driver server to start.
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.4.1'
Driver info: driver.version: unknown
Exception in thread "main" java.lang.IllegalStateException: should never be reached
	at Main.main(Main.java:25)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:982)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:929)
    at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:457)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

@joerg1985 joerg1985 changed the title ensure all states of StartOrDie are handled [grid] ensure all states of StartOrDie are handled Nov 23, 2022
Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @joerg1985!

DriverService.start did not fail, if the execution of the driver process
was never started or the process did not bind the port.
@sonarcloud
Copy link

sonarcloud bot commented Dec 5, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@diemol diemol merged commit 4af3726 into SeleniumHQ:trunk Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants