title: Selenium Grid hits command timeout Before newSessionWaitTimeout
body: <h2>Problem</h2>
  
  <p>In my selenium grid setup, my session requests (that are waiting for empty slots to become available) timeout before hitting the <code>newSessionWaitTimeout</code> because they are hitting the RemoteWebDriver command timeout.</p>
  
  <hr>
  
  <h2>Details</h2>
  
  <p>I sometimes have more tests trying to run than available slots on my nodes. This is supposed to be <strong>fine</strong> as the tests trying to get a new session on an available slot get queued up until a slot is free. I can see this happening correctly in my grid console (example message below).</p>
  
  <blockquote>
    <p>3 requests waiting for a slot to be free.
    Capabilities [{browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]Capabilities [{browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]Capabilities [{browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]</p>
  </blockquote>
  
  <p>However, these requests timeout after the webdriver's command timeout period, <strong>effectively ignoring</strong> the <code>newSessionWaitTimeout</code> setting. My <code>newSessionWaitTimeout</code> is set to the default <code>-1</code> to allow indefinite waiting for a slot. The webdriver command timeout <a href="https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Remote/RemoteWebDriver.cs#L68" rel="nofollow noreferrer">defaults to 60 seconds</a>.</p>
  
  <blockquote>
    <p>OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://{myHubIP}:4444/wd/hub/session timed out after 60 seconds.
      ----> System.Net.WebException : The operation has timed out
      Exception doesn't have a stacktrace</p>
  </blockquote>
  
  <p>I can increase the driver's timeout to some large amount that's greater than what my tests might possibly need to wait for to get a slot, but that will affect every command the driver executes. It seems unreasonable to have to basically remove command timeouts to make sure my tests don't timeout while just waiting for an open slot, especially when there's a specific setting that's supposed to handle the timeout for a waiting session. </p>
  
  <p>So, I feel like I'm somehow missing something...</p>
  
  <hr>
  
  <h2>Testing / Sanity Checks</h2>
  
  <p>I tested to make sure my <code>newSessionWaitTimeout</code> was actually working by dropping the value under the 60 second timeout I was seeing (dropped it to 10 seconds). Doing this while running more tests than open slots gave me the expected error after 10 seconds, right on cue.</p>
  
  <blockquote>
    <p>System.InvalidOperationException : Error forwarding the new session Request timed out waiting for a node to become available.
       at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
       at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
       at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
       at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
       at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)</p>
  </blockquote>
  
  <p>So from this I can see the <code>newSessionWaitTimeout</code> works fine if it's limit is actually reached. </p>
  
  <p>Running the same test with the <code>newSessionWaitTimeout</code> either below 0 (indefinite wait) or anything above the driver command timeout (default 60 seconds) never hits the above error because the request times out first. Instead is gives the error I listed in the Overview section above.</p>
  
  <p>Now, if I increase the timeout of the RemoteWebDriver, I can see that this is the timeout that I'm hitting when waiting for my new sessions. For example, if I initialize my RemoteWebDriver with 
  <code>new RemoteWebDriver(new Uri($"http://{myHubIP}:4444/wd/hub"), capabilities, TimeSpan.FromMinutes(3));</code> then I get the error:</p>
  
  <blockquote>
    <p>OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://{myHubIP}:4444/wd/hub/session timed out after 180 seconds.
      ----> System.Net.WebException : The operation has timed out
      Exception doesn't have a stacktrace</p>
  </blockquote>
  
  <p>Again, if I bump that value up enough (could need to be very large if I have lots of tests to run) it solves my waiting sessions problem but now all driver commands run the risk of being hung for a very long time. Any ideas on how to get around this correctly (this seems incorrect)?</p>
  
  <p>I'm using Selenium WebDriver and server standalone 3.0.1</p>