<p>I'm currently running in to this exception when I run several tests in parallel against a selenium grid that is deployed using K8s.  I have deployed clusters in both AWS and Azure and received the same error.  The error occurs when I try to run more tests than there are nodes, I can run a few tests successfully, then after a short amount of time, it will fail all of the remaining tests with this error.</p>

<blockquote>
  <p>OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL xxxxxx.xxx.xxx/wd/hub/session. The status of the exception was ConnectionClosed, and the message was: The underlying connection was closed: The connection was closed unexpectedly.</p>
</blockquote>

<p>I have adjusted timeouts on the selenium hub(browser timeout, timeout, newsesssiontimeout) as well as the command timeouts from the remotewebdriver and nothing changes.   I also do not get the error when I test locally. </p>

<p>Here is my current stack.</p>

<ul>
<li>RemoteWebdriver: 3.14.0</li>
<li>Selenium Hub : 3.14.0</li>
<li>Selenium Node : 3.14.0</li>
<li>Chrome : 69</li>
<li>C#/Nunit</li>
<li>AKS/EKS </li>
</ul>

<p>Code:</p>

<pre><code>    [TestCaseSource(typeof(MyFactoryClass), nameof(MyFactoryClass.TestCases))]
    public void ZaleniumTest(int x)
    {
        var caps = new DesiredCapabilities();
        caps.SetCapability("browserName", "chrome");
        var driver =
            new RemoteWebDriver(new Uri(Url), caps, TimeSpan.FromSeconds(1200)) {Url = "http://www.google.com"};
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1200);
        var query = driver.FindElement(By.Name("q"));
        query.SendKeys("Cheese");
        query.Submit();
        System.Threading.Thread.Sleep(3000);
        Assert.IsTrue(driver.Title.Contains("Google"));
        driver.Quit();
    }      
</code></pre>

<p>Here are the commands that I run to deploy the grid:</p>

<pre><code>    kubectl run selenium-hub --image selenium/hub:latest --port 4444
    kubectl expose deployment selenium-hub --type=LoadBalancer
    kubectl run selenium-node-chrome --image selenium/node-chrome:latest --env="HUB_PORT_4444_TCP_ADDR=selenium-hub" --env="HUB_PORT_4444_TCP_PORT=4444"
</code></pre>

<p>With this simple grid set up(1 hub 1 chrome node) I try to run 20 tests with the expectation that the tests will be queued up.  After about 10 passing tests, the test run will fail and produce that error.</p>

<p>I am looking for the correct places to add a wait or a time out so that we can handle the test queue correctly. </p>

<p>Thanks in advance. </p>

<p>I was able to locate the issue.  It turns out there is a idle timeout setting for the load balancers both in AWS and Azure.  It was set to 60 seconds for my case in AWS.  I turned the timeout to 3600 seconds and that seemed to fix the problem.  </p>
