[grid] Only pass available hosts to the host selector
package org.openqa.selenium.grid.distributor;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.grid.data.CreateSessionRequest;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import static com.google.common.collect.ImmutableSet.toImmutableSet;
+import static org.openqa.selenium.grid.distributor.model.Host.Status.UP;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES;
import static org.openqa.selenium.remote.RemoteTags.CAPABILITIES_EVENT;
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
@@ -178,7 +181,10 @@ public CreateSessionResponse newSession(HttpRequest request)
writeLock.lock();
try {
// Find a host that supports the capabilities present in the new session
- Optional<Host> selectedHost = hostSelector.selectHost(firstRequest.getCapabilities(), getModel());
+ ImmutableSet<Host> availableHosts = getModel().stream()
+ .filter(host -> UP.equals(host.getHostStatus()))
+ .collect(toImmutableSet());
+ Optional<Host> selectedHost = hostSelector.selectHost(firstRequest.getCapabilities(), availableHosts);
// Reserve some space for this session
selected = selectedHost.map(host -> host.reserve(firstRequest));
