Skip to content

Commit

Permalink
[grid] Using session request timeout in the RouterServer
Browse files Browse the repository at this point in the history
When a new session request comes, the Router forwards it
to the SessionQueue, and the new session request will stay
in the queue up to 300 seconds (default). However, the read
timeout in the http client is 180 seconds (default), so
the request will timeout in the Router first. Which is why
we need to use the configured new session request timeout.

Fixes SeleniumHQ/docker-selenium#1377
  • Loading branch information
diemol committed Sep 6, 2021
1 parent 4259e96 commit db2bb9e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

package org.openqa.selenium.grid.router.httpd;

import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_MAP_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;
import static org.openqa.selenium.net.Urls.fromUri;
import static org.openqa.selenium.remote.http.Route.combine;
import static org.openqa.selenium.remote.http.Route.get;

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -48,27 +58,19 @@
import org.openqa.selenium.grid.sessionqueue.remote.RemoteNewSessionQueue;
import org.openqa.selenium.grid.web.GridUiRoute;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.Routable;
import org.openqa.selenium.remote.http.Route;
import org.openqa.selenium.remote.tracing.Tracer;

import java.net.URL;
import java.time.Duration;
import java.util.Collections;
import java.util.Set;
import java.util.logging.Logger;

import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static org.openqa.selenium.grid.config.StandardGridRoles.DISTRIBUTOR_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_MAP_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;
import static org.openqa.selenium.net.Urls.fromUri;
import static org.openqa.selenium.remote.http.Route.combine;
import static org.openqa.selenium.remote.http.Route.get;

@AutoService(CliCommand.class)
public class RouterServer extends TemplateGridServerCommand {

Expand Down Expand Up @@ -124,11 +126,16 @@ protected Handlers createHandlers(Config config) {
SessionMapOptions sessionsOptions = new SessionMapOptions(config);
SessionMap sessions = sessionsOptions.getSessionMap();

NewSessionQueueOptions sessionQueueOptions = new NewSessionQueueOptions(config);
URL sessionQueueUrl = fromUri(sessionQueueOptions.getSessionQueueUri());
NewSessionQueueOptions newSessionQueueOptions = new NewSessionQueueOptions(config);
URL sessionQueueUrl = fromUri(newSessionQueueOptions.getSessionQueueUri());
Duration sessionRequestTimeout = newSessionQueueOptions.getSessionRequestTimeout();
ClientConfig httpClientConfig = ClientConfig
.defaultConfig()
.baseUrl(sessionQueueUrl)
.readTimeout(sessionRequestTimeout);
NewSessionQueue queue = new RemoteNewSessionQueue(
tracer,
clientFactory.createClient(sessionQueueUrl),
clientFactory.createClient(httpClientConfig),
secret);

DistributorOptions distributorOptions = new DistributorOptions(config);
Expand Down

3 comments on commit db2bb9e

@bgrgincic
Copy link

@bgrgincic bgrgincic commented on db2bb9e Sep 7, 2021

Choose a reason for hiding this comment

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

@diemol was this perhaps included in 4.0.0-rc-2-prerelease-20210906 ? I'm not seeing it mentioned anywhere.

@diemol
Copy link
Member Author

@diemol diemol commented on db2bb9e Sep 7, 2021

Choose a reason for hiding this comment

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

Yes, the commit hash in the Server version is the reference.

@bgrgincic
Copy link

@bgrgincic bgrgincic commented on db2bb9e Sep 7, 2021

Choose a reason for hiding this comment

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

Thank you, I somehow missed it.

Please sign in to comment.