@@ -303,7 +303,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
303
303
304
304
// Identify possible slots to use as quickly as possible to enable concurrent session starting
305
305
SessionSlot slotToUse = null ;
306
- synchronized (factories ) {
306
+ synchronized (factories ) {
307
307
for (SessionSlot factory : factories ) {
308
308
if (!factory .isAvailable () || !factory .test (sessionRequest .getCapabilities ())) {
309
309
continue ;
@@ -323,36 +323,35 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
323
323
new RetrySessionRequestException ("No slot matched the requested capabilities. All slots are busy." ));
324
324
}
325
325
326
- Optional <ActiveSession > possibleSession = slotToUse .apply (sessionRequest );
327
-
328
- if (!possibleSession .isPresent ()) {
326
+ Either <WebDriverException , ActiveSession > possibleSession = slotToUse .apply (sessionRequest );
327
+
328
+ if (possibleSession .isRight ()) {
329
+ ActiveSession session = possibleSession .right ();
330
+ currentSessions .put (session .getId (), slotToUse );
331
+
332
+ SessionId sessionId = session .getId ();
333
+ Capabilities caps = session .getCapabilities ();
334
+ SESSION_ID .accept (span , sessionId );
335
+ CAPABILITIES .accept (span , caps );
336
+ String downstream = session .getDownstreamDialect ().toString ();
337
+ String upstream = session .getUpstreamDialect ().toString ();
338
+ String sessionUri = session .getUri ().toString ();
339
+ span .setAttribute (AttributeKey .DOWNSTREAM_DIALECT .getKey (), downstream );
340
+ span .setAttribute (AttributeKey .UPSTREAM_DIALECT .getKey (), upstream );
341
+ span .setAttribute (AttributeKey .SESSION_URI .getKey (), sessionUri );
342
+
343
+ // The session we return has to look like it came from the node, since we might be dealing
344
+ // with a webdriver implementation that only accepts connections from localhost
345
+ Session externalSession = createExternalSession (session , externalUri , slotToUse .isSupportingCdp ());
346
+ return Either .right (new CreateSessionResponse (
347
+ externalSession ,
348
+ getEncoder (session .getDownstreamDialect ()).apply (externalSession )));
349
+ } else {
329
350
slotToUse .release ();
330
351
span .setAttribute ("error" , true );
331
- span .setStatus (Status .NOT_FOUND );
332
352
span .addEvent ("Unable to create session with the driver" , attributeMap );
333
- return Either .left (new SessionNotCreatedException ( "Unable to create session with the driver" ));
353
+ return Either .left (possibleSession . left ( ));
334
354
}
335
-
336
- ActiveSession session = possibleSession .get ();
337
- currentSessions .put (session .getId (), slotToUse );
338
-
339
- SessionId sessionId = session .getId ();
340
- Capabilities caps = session .getCapabilities ();
341
- SESSION_ID .accept (span , sessionId );
342
- CAPABILITIES .accept (span , caps );
343
- String downstream = session .getDownstreamDialect ().toString ();
344
- String upstream = session .getUpstreamDialect ().toString ();
345
- String sessionUri = session .getUri ().toString ();
346
- span .setAttribute (AttributeKey .DOWNSTREAM_DIALECT .getKey (), downstream );
347
- span .setAttribute (AttributeKey .UPSTREAM_DIALECT .getKey (), upstream );
348
- span .setAttribute (AttributeKey .SESSION_URI .getKey (), sessionUri );
349
-
350
- // The session we return has to look like it came from the node, since we might be dealing
351
- // with a webdriver implementation that only accepts connections from localhost
352
- Session externalSession = createExternalSession (session , externalUri , slotToUse .isSupportingCdp ());
353
- return Either .right (new CreateSessionResponse (
354
- externalSession ,
355
- getEncoder (session .getDownstreamDialect ()).apply (externalSession )));
356
355
}
357
356
}
358
357
0 commit comments