Skip to content

Commit 40669b6

Browse files
committed
[grid] Restoring behavior for session creation interval.
A bug was introduced in 4.4 where session creation was executed every 15s by default. This fix reverts that, and now session creation is tried every 15 milliseconds. Additionally, the flag `session-request-timeout-period` was introduced, to allow users to configure how often timeouts for new session are checked. Fixes #10984 Fixes SeleniumHQ/docker-selenium#1690
1 parent adf498c commit 40669b6

File tree

6 files changed

+49
-32
lines changed

6 files changed

+49
-32
lines changed

java/src/org/openqa/selenium/grid/commands/Hub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected Handlers createHandlers(Config config) {
149149
NewSessionQueue queue = new LocalNewSessionQueue(
150150
tracer,
151151
distributorOptions.getSlotMatcher(),
152-
newSessionRequestOptions.getSessionRequestRetryInterval(),
152+
newSessionRequestOptions.getSessionRequestTimeoutPeriod(),
153153
newSessionRequestOptions.getSessionRequestTimeout(),
154154
secret);
155155
handler.addHandler(queue);

java/src/org/openqa/selenium/grid/commands/Standalone.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import java.net.URI;
6666
import java.net.URL;
6767
import java.util.Collections;
68-
import java.util.Optional;
6968
import java.util.Set;
7069
import java.util.logging.Level;
7170
import java.util.logging.Logger;
@@ -149,7 +148,7 @@ protected Handlers createHandlers(Config config) {
149148
NewSessionQueue queue = new LocalNewSessionQueue(
150149
tracer,
151150
distributorOptions.getSlotMatcher(),
152-
newSessionRequestOptions.getSessionRequestRetryInterval(),
151+
newSessionRequestOptions.getSessionRequestTimeoutPeriod(),
153152
newSessionRequestOptions.getSessionRequestTimeout(),
154153
registrationSecret);
155154
combinedHandler.addHandler(queue);

java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueFlags.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
package org.openqa.selenium.grid.sessionqueue.config;
1919

20-
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;
21-
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.DEFAULT_REQUEST_TIMEOUT;
22-
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.DEFAULT_RETRY_INTERVAL;
23-
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.SESSION_QUEUE_SECTION;
24-
2520
import com.google.auto.service.AutoService;
2621

2722
import com.beust.jcommander.Parameter;
@@ -34,6 +29,12 @@
3429
import java.util.Collections;
3530
import java.util.Set;
3631

32+
import static org.openqa.selenium.grid.config.StandardGridRoles.SESSION_QUEUE_ROLE;
33+
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.DEFAULT_REQUEST_TIMEOUT;
34+
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.DEFAULT_REQUEST_TIMEOUT_PERIOD;
35+
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.DEFAULT_RETRY_INTERVAL;
36+
import static org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions.SESSION_QUEUE_SECTION;
37+
3738
@SuppressWarnings("FieldMayBeFinal")
3839
@AutoService(HasRoles.class)
3940
public class NewSessionQueueFlags implements HasRoles {
@@ -63,11 +64,17 @@ public class NewSessionQueueFlags implements HasRoles {
6364
@ConfigValue(section = SESSION_QUEUE_SECTION, name = "session-request-timeout", example = "5")
6465
private int sessionRequestTimeout = DEFAULT_REQUEST_TIMEOUT;
6566

67+
@Parameter(
68+
names = {"--session-request-timeout-period"},
69+
description = "In seconds, how often the timeout for new session requests is checked.")
70+
@ConfigValue(section = SESSION_QUEUE_SECTION, name = "session-request-timeout-period", example = "5")
71+
private int sessionRequestTimeoutPeriod = DEFAULT_REQUEST_TIMEOUT_PERIOD;
72+
6673
@Parameter(
6774
names = {"--session-retry-interval"},
68-
description = "Retry interval in seconds. If all slots are busy, new session request " +
69-
"will be retried after the given interval.")
70-
@ConfigValue(section = SESSION_QUEUE_SECTION, name = "session-retry-interval", example = "5")
75+
description = "Session creation interval in milliseconds. If all slots are busy, new session "
76+
+ "request will be retried after the given interval.")
77+
@ConfigValue(section = SESSION_QUEUE_SECTION, name = "session-retry-interval", example = "15")
7178
private int sessionRetryInterval = DEFAULT_RETRY_INTERVAL;
7279

7380
@Override

java/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueOptions.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class NewSessionQueueOptions {
3535

3636
static final String SESSION_QUEUE_SECTION = "sessionqueue";
3737
static final int DEFAULT_REQUEST_TIMEOUT = 300;
38+
static final int DEFAULT_REQUEST_TIMEOUT_PERIOD = 10;
3839
static final int DEFAULT_RETRY_INTERVAL = 15;
3940

4041
private final Config config;
@@ -96,23 +97,33 @@ public Duration getSessionRequestTimeout() {
9697
return Duration.ofSeconds(timeout);
9798
}
9899

100+
public Duration getSessionRequestTimeoutPeriod() {
101+
// If the user sets 0 or less, we default to 1s.
102+
int timeout = Math.max(
103+
config.getInt(SESSION_QUEUE_SECTION, "session-request-timeout-period")
104+
.orElse(DEFAULT_REQUEST_TIMEOUT_PERIOD),
105+
1);
106+
107+
return Duration.ofSeconds(timeout);
108+
}
109+
99110
public Duration getSessionRequestRetryInterval() {
100-
// If the user sets 0 or less, we default to 0s.
111+
// If the user sets 0 or less, we default to DEFAULT_RETRY_INTERVAL (in milliseconds).
101112
int interval = Math.max(
102113
config.getInt(SESSION_QUEUE_SECTION, "session-retry-interval")
103114
.orElse(DEFAULT_RETRY_INTERVAL),
104-
0);
105-
return Duration.ofSeconds(interval);
115+
DEFAULT_RETRY_INTERVAL);
116+
return Duration.ofMillis(interval);
106117
}
107118

108119
@ManagedAttribute(name = "RequestTimeoutSeconds")
109120
public long getRequestTimeoutSeconds() {
110121
return getSessionRequestTimeout().getSeconds();
111122
}
112123

113-
@ManagedAttribute(name = "RetryIntervalSeconds")
114-
public long getRetryIntervalSeconds() {
115-
return getSessionRequestRetryInterval().getSeconds();
124+
@ManagedAttribute(name = "RetryIntervalMilliseconds")
125+
public long getRetryIntervalMilliseconds() {
126+
return getSessionRequestRetryInterval().toMillis();
116127
}
117128

118129
public NewSessionQueue getSessionQueue(String implementation) {

java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.common.collect.ImmutableSet;
2323

2424
import org.openqa.selenium.Capabilities;
25-
import org.openqa.selenium.ImmutableCapabilities;
2625
import org.openqa.selenium.SessionNotCreatedException;
2726
import org.openqa.selenium.concurrent.GuardedRunnable;
2827
import org.openqa.selenium.grid.config.Config;
@@ -114,13 +113,13 @@ public class LocalNewSessionQueue extends NewSessionQueue implements Closeable {
114113
public LocalNewSessionQueue(
115114
Tracer tracer,
116115
SlotMatcher slotMatcher,
117-
Duration retryPeriod,
116+
Duration requestTimeoutCheck,
118117
Duration requestTimeout,
119118
Secret registrationSecret) {
120119
super(tracer, registrationSecret);
121120

122121
this.slotMatcher = Require.nonNull("Slot matcher", slotMatcher);
123-
Require.nonNegative("Retry period", retryPeriod);
122+
Require.nonNegative("Retry period", requestTimeoutCheck);
124123

125124
this.requestTimeout = Require.positive("Request timeout", requestTimeout);
126125

@@ -130,8 +129,8 @@ public LocalNewSessionQueue(
130129

131130
service.scheduleAtFixedRate(
132131
GuardedRunnable.guard(this::timeoutSessions),
133-
retryPeriod.toMillis(),
134-
retryPeriod.toMillis(),
132+
requestTimeoutCheck.toMillis(),
133+
requestTimeoutCheck.toMillis(),
135134
MILLISECONDS);
136135

137136
new JMXHelper().register(this);
@@ -148,7 +147,7 @@ public static NewSessionQueue create(Config config) {
148147
return new LocalNewSessionQueue(
149148
tracer,
150149
slotMatcher,
151-
newSessionQueueOptions.getSessionRequestRetryInterval(),
150+
newSessionQueueOptions.getSessionRequestTimeoutPeriod(),
152151
newSessionQueueOptions.getSessionRequestTimeout(),
153152
secretOptions.getRegistrationSecret());
154153
}

java/test/org/openqa/selenium/grid/router/JmxTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
import org.openqa.selenium.remote.tracing.DefaultTestTracer;
4545
import org.openqa.selenium.remote.tracing.Tracer;
4646

47+
import java.lang.management.ManagementFactory;
48+
import java.net.URI;
49+
import java.net.URISyntaxException;
50+
import java.time.Duration;
51+
import java.time.Instant;
52+
import java.util.logging.Logger;
53+
4754
import javax.management.AttributeNotFoundException;
4855
import javax.management.InstanceNotFoundException;
4956
import javax.management.IntrospectionException;
@@ -54,12 +61,6 @@
5461
import javax.management.MalformedObjectNameException;
5562
import javax.management.ObjectName;
5663
import javax.management.ReflectionException;
57-
import java.lang.management.ManagementFactory;
58-
import java.net.URI;
59-
import java.net.URISyntaxException;
60-
import java.time.Duration;
61-
import java.time.Instant;
62-
import java.util.logging.Logger;
6364

6465
import static org.assertj.core.api.Assertions.assertThat;
6566
import static org.junit.jupiter.api.Assertions.fail;
@@ -163,7 +164,7 @@ void shouldBeAbleToRegisterNode() throws URISyntaxException {
163164
}
164165

165166
@Test
166-
void shouldBeAbleToRegisterSessionQueuerServerConfig() {
167+
void shouldBeAbleToRegisterSessionQueueServerConfig() {
167168
try {
168169
ObjectName name = new ObjectName(
169170
"org.seleniumhq.grid:type=Config,name=NewSessionQueueConfig");
@@ -182,9 +183,9 @@ void shouldBeAbleToRegisterSessionQueuerServerConfig() {
182183
assertThat(Long.parseLong(requestTimeout))
183184
.isEqualTo(newSessionQueueOptions.getRequestTimeoutSeconds());
184185

185-
String retryInterval = (String) beanServer.getAttribute(name, "RetryIntervalSeconds");
186+
String retryInterval = (String) beanServer.getAttribute(name, "RetryIntervalMilliseconds");
186187
assertThat(Long.parseLong(retryInterval))
187-
.isEqualTo(newSessionQueueOptions.getRetryIntervalSeconds());
188+
.isEqualTo(newSessionQueueOptions.getRetryIntervalMilliseconds());
188189
} catch (InstanceNotFoundException | IntrospectionException | ReflectionException
189190
| MalformedObjectNameException e) {
190191
fail("Could not find the registered MBean");

0 commit comments

Comments
 (0)