[java] skip browser-restricted ports when picking a free port#17561
Conversation
Review Summary by QodoSkip browser-restricted ports in PortProber
WalkthroughsDescription• Prevents PortProber from assigning browser-restricted ports • Adds hardcoded list of unsafe ports from Firefox/Chromium • Increases retry attempts from 5 to 10 iterations • Skips port selection if restricted port is randomly chosen Diagramflowchart LR
A["findFreePort()"] --> B["createAcceptablePort()"]
B --> C{"isBrowserRestrictedPort?"}
C -->|Yes| D["continue to next iteration"]
C -->|No| E["checkPortIsFree()"]
E --> F["return port or retry"]
D --> B
File Changes1. java/src/org/openqa/selenium/net/PortProber.java
|
Code Review by Qodo
1. Restricted ports waste retries
|
There was a problem hiding this comment.
Pull request overview
Prevents Java’s PortProber from selecting ports that modern browsers refuse to connect to (avoiding intermittent “unsafe/denied port” navigation failures in tests and local servers).
Changes:
- Add a browser-restricted port allowlist check (
BROWSER_RESTRICTED_PORTS+isBrowserRestrictedPort). - Skip restricted ports when selecting a candidate free port; increase retry attempts from 5 to 10.
- Run
./go formatbefore pushing to avoid formatter-related CI failures.
|
Persistent review updated to latest commit 6666e54 |
|
Persistent review updated to latest commit 13522c1 |
|
Persistent review updated to latest commit 38e9a8e |
Was getting flaky tests from https://github.com/SeleniumHQ/selenium/actions/runs/26340150176/job/77540628162?pr=17559
Tracked down this as the root cause: Firefox has a hard-coded banned-port list and refuses to navigate
Not sure how common this is or if my PR just got unlucky.
💥 What does this PR do?
🤖 AI assistance
💡 Additional Considerations
Probably can do this for other bindings as well.
🔄 Types of changes