|
71 | 71 | import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;
|
72 | 72 | import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
|
73 | 73 | import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;
|
| 74 | +import org.openqa.selenium.internal.Debug; |
74 | 75 | import org.openqa.selenium.internal.Either;
|
75 | 76 | import org.openqa.selenium.internal.Require;
|
76 | 77 | import org.openqa.selenium.remote.SessionId;
|
@@ -436,7 +437,10 @@ public Either<SessionNotCreatedException, CreateSessionResponse> newSession(Sess
|
436 | 437 | // in this next block of code.
|
437 | 438 | SlotId selectedSlot = reserveSlot(request.getRequestId(), caps);
|
438 | 439 | if (selectedSlot == null) {
|
439 |
| - LOG.info(String.format("Unable to find slot for request %s. May retry: %s ", request.getRequestId(), caps)); |
| 440 | + LOG.info( |
| 441 | + String.format("Unable to find a free slot for request %s. %s ", |
| 442 | + request.getRequestId(), |
| 443 | + caps)); |
440 | 444 | retry = true;
|
441 | 445 | continue;
|
442 | 446 | }
|
@@ -595,35 +599,37 @@ private class NewSessionRunnable implements Runnable {
|
595 | 599 |
|
596 | 600 | @Override
|
597 | 601 | public void run() {
|
598 |
| - List<SessionRequestCapability> queueContents = sessionQueue.getQueueContents(); |
599 |
| - if (rejectUnsupportedCaps) { |
600 |
| - checkMatchingSlot(queueContents); |
601 |
| - } |
602 |
| - int initialSize = queueContents.size(); |
603 |
| - boolean retry = initialSize != 0; |
604 |
| - |
605 |
| - while (retry) { |
| 602 | + boolean loop = true; |
| 603 | + while (loop) { |
606 | 604 | // We deliberately run this outside of a lock: if we're unsuccessful
|
607 | 605 | // starting the session, we just put the request back on the queue.
|
608 | 606 | // This does mean, however, that under high contention, we might end
|
609 | 607 | // up starving a session request.
|
610 | 608 | Set<Capabilities> stereotypes =
|
611 |
| - getAvailableNodes().stream() |
612 |
| - .filter(NodeStatus::hasCapacity) |
613 |
| - .map( |
614 |
| - node -> |
615 |
| - node.getSlots().stream() |
616 |
| - .map(Slot::getStereotype) |
617 |
| - .collect(Collectors.toSet())) |
618 |
| - .flatMap(Collection::stream) |
619 |
| - .collect(Collectors.toSet()); |
620 |
| - |
621 |
| - Optional<SessionRequest> maybeRequest = sessionQueue.getNextAvailable(stereotypes); |
622 |
| - maybeRequest.ifPresent(req -> sessionCreatorExecutor.execute(() -> handleNewSessionRequest(req))); |
623 |
| - |
624 |
| - int currentSize = sessionQueue.getQueueContents().size(); |
625 |
| - retry = currentSize != 0 && currentSize != initialSize; |
626 |
| - initialSize = currentSize; |
| 609 | + getAvailableNodes() |
| 610 | + .stream() |
| 611 | + .filter(NodeStatus::hasCapacity) |
| 612 | + .map( |
| 613 | + node -> |
| 614 | + node |
| 615 | + .getSlots() |
| 616 | + .stream() |
| 617 | + .map(Slot::getStereotype) |
| 618 | + .collect(Collectors.toSet())) |
| 619 | + .flatMap(Collection::stream) |
| 620 | + .collect(Collectors.toSet()); |
| 621 | + |
| 622 | + if (!stereotypes.isEmpty()) { |
| 623 | + Optional<SessionRequest> maybeRequest = sessionQueue.getNextAvailable(stereotypes); |
| 624 | + maybeRequest.ifPresent( |
| 625 | + req -> sessionCreatorExecutor.execute(() -> handleNewSessionRequest(req))); |
| 626 | + loop = maybeRequest.isPresent(); |
| 627 | + } else { |
| 628 | + loop = false; |
| 629 | + } |
| 630 | + } |
| 631 | + if (rejectUnsupportedCaps) { |
| 632 | + checkMatchingSlot(sessionQueue.getQueueContents()); |
627 | 633 | }
|
628 | 634 | }
|
629 | 635 |
|
@@ -659,7 +665,8 @@ private void handleNewSessionRequest(SessionRequest sessionRequest) {
|
659 | 665 |
|
660 | 666 | if (response.isLeft() && response.left() instanceof RetrySessionRequestException) {
|
661 | 667 | try(Span childSpan = span.createSpan("distributor.retry")) {
|
662 |
| - LOG.info("Retrying"); |
| 668 | + LOG.log(Debug.getDebugLogLevel(), |
| 669 | + String.format("Retrying %s", sessionRequest.getDesiredCapabilities())); |
663 | 670 | boolean retried = sessionQueue.retryAddToQueue(sessionRequest);
|
664 | 671 |
|
665 | 672 | attributeMap.put("request.retry_add", EventAttribute.setValue(retried));
|
|
0 commit comments