Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: WebSocket Path Not Working with Selenium Grid --sub-path Option #13393

Closed
hil00137 opened this issue Jan 4, 2024 · 17 comments · Fixed by #13407
Closed

[🐛 Bug]: WebSocket Path Not Working with Selenium Grid --sub-path Option #13393

hil00137 opened this issue Jan 4, 2024 · 17 comments · Fixed by #13407

Comments

@hil00137
Copy link

hil00137 commented Jan 4, 2024

What happened?

Description:
After setting up Selenium Grid with the --sub-path=/selenium-grid option, I encountered an issue with the WebSocket path. Previously, I was able to access the WebSocket using the path ws://ip:port/sessions/{ID}/se/vnc. However, after adding the --sub-path option, the expected WebSocket path ws://ip:port/selenium-grid/sessions/{ID}/se/vnc does not work.

Steps to Reproduce:

  1. Start Selenium Grid with the --sub-path=/selenium-grid option.
  2. Attempt to access the WebSocket at ws://ip:port/selenium-grid/sessions/{ID}/se/vnc.

Expected Behavior:
The WebSocket should be accessible at the path ws://ip:port/selenium-grid/sessions/{ID}/se/vnc, reflecting the --sub-path configuration.

Actual Behavior:
The WebSocket path ws://ip:port/selenium-grid/sessions/{ID}/se/vnc is not functional, and there seems to be no alternative path that accommodates the --sub-path configuration.

Additional Information:

  • This issue seems to specifically relate to the interaction between the WebSocket and the --sub-path option in Selenium Grid.
  • Any guidance or workaround to address this issue would be greatly appreciated.

If there is no sub-path option available, could you please inform me of any other methods to set a sub-path specifically for WebSocket connections? I would greatly appreciate your guidance on this.

Thank you for your assistance in resolving this matter.

How can we reproduce the issue?

1. Configured and launched selenium-hub in Docker with `SE_SUB_PATH=/selenium/`.
2. Set up the Selenium Grid and confirmed manager UI accessibility at `http://ip:port/selenium/#ui`.
3. Ran a JUnit Test with RemoteWebDriver and confirmed the test was executing. For ease of testing, I included a Thread.sleep(10000); statement to allow sufficient time for observation.
4. Attempted to monitor the test using VNC:
   - The VNC request from the manager interface connects to an URL without the `/selenium` prefix.
   - Direct VNC connection to `ws://ip:port/session/{ID}/se/vnc` is successful.
   - However, attempting a VNC connection to `ws://ip:port/selenium/session/{ID}/se/vnc` fails to establish a connection.

Relevant log output

Not Important

Operating System

WSL2 with selenium docker

Selenium version

Java 4.16.1

What are the browser(s) and version(s) where you see this issue?

Chrome 119

What are the browser driver(s) and version(s) where you see this issue?

Not Important

Are you using Selenium Grid?

4.16.1

Copy link

github-actions bot commented Jan 4, 2024

@hil00137, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Jan 4, 2024

Does it work if you do not use Docker?

@diemol
Copy link
Member

diemol commented Jan 4, 2024

@VietND96 do you know? I believe this was fixed.

@hil00137
Copy link
Author

hil00137 commented Jan 5, 2024

@diemol
I executed the Selenium hub using the command below and found the same issue as when running it through Docker.

java -jar selenium-sever-4.16.1.jar hub --sub-path /selenium/

Screenshots showing the sub-path added to the manager launched via command line.
Screenshot 2024-01-05 at 10.34.48

When requesting the WebSocket URL without /selenium/
Screenshot 2024-01-05 at 10.51.20

When requesting the WebSocket URL with /selenium/
스크린샷 2024-01-05 오전 10 55 50

@VietND96
Copy link
Member

VietND96 commented Jan 5, 2024

Looks like my fix only works when there is ingress configured upfront - as the comment and reproduce #12791 (comment)
For docker standalone, or start locally via java -jar, the issue still present

@hil00137
Copy link
Author

hil00137 commented Jan 5, 2024

@VietND96
I've kept the hub running in the -jar form and configured docker-nodes with the following command:

docker run -p 5555:5555 -e SE_EVENT_BUS_HOST=<hub-ip> \
 -e SE_EVENT_BUS_PUBLISH_PORT=4442 \ 
 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
 -e SE_VNC_NO_PASSWORD=1 \ 
 -e SE_VNC_VIEW_ONLY=1 \
 -e SE_NODE_GRID_URL=http://<hub-ip>:4444/selenium \
 -v ${PWD}/selenium-http-jdk-client.jar:/opt/selenium/selenium-http-jdk-client.jar \ 
 -v ${PWD}/config.toml:/opt/bin/config.toml \
 -v /var/run/docker.sock:/var/run/docker.sock \
 selenium/node-docker:4.16.1

The contents of config.toml are as follows:

[docker]
configs = [
  "selenium/standalone-chrome:120.0", '{"browserName": "chrome", "browserVersion": "120.0"}',
  ....
]

[server]
host = "<node-ip>"
port = 5555

In this setup, when attempting a VNC connection from the manager, it tries to connect to the URL with /selenium appended. However, the actual successful connection can only be established to the URL without /selenium.

manager request like this. but failed connect
스크린샷 2024-01-05 오후 6 14 19

I tried without /selenium, success connect
스크린샷 2024-01-05 오후 6 13 37

I am currently testing to set up a Selenium Grid using Docker nodes as shown above.

@VietND96
Copy link
Member

VietND96 commented Jan 5, 2024

I suspect something around here

matching(req -> req.getUri().startsWith("/session/")).to(() -> sessionHandler));

@joerg1985, do you have any idea on this? do we need to add Route.prefix in case subPath present in Router config?

@diemol
Copy link
Member

diemol commented Jan 7, 2024

Not sure it is there, maybe it is around ProxyNodeWebsockets.

@VietND96
Copy link
Member

VietND96 commented Jan 8, 2024

Not sure it is there, maybe it is around ProxyNodeWebsockets.

@diemol, you're correct. I raise PR #13407 to fix it.

@VietND96
Copy link
Member

VietND96 commented Jan 8, 2024

Hi @hil00137, if you have time, can you do a test with my image containing the fix from namespace ndviet/<image>:latest and confirm?
All configs are the same as you mentioned in the above comment

@hil00137
Copy link
Author

hil00137 commented Jan 8, 2024

@VietND96
It appears that when attempting a WebSocket connection, it tries to connect using a URL with /selenium appended.

docker run -p 5555:5555 -e SE_EVENT_BUS_HOST=<hub-ip> \
 -e SE_EVENT_BUS_PUBLISH_PORT=4442 \ 
 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 \
 -e SE_VNC_NO_PASSWORD=1 \ 
 -e SE_VNC_VIEW_ONLY=1 \
 -e SE_NODE_GRID_URL=http://<hub-ip>:4444/selenium \
 -v ${PWD}/selenium-http-jdk-client.jar:/opt/selenium/selenium-http-jdk-client.jar \ 
 -v ${PWD}/config.toml:/opt/bin/config.toml \
 -v /var/run/docker.sock:/var/run/docker.sock \
 ndviet/node-docker:latest

Configuration for config.toml:

[docker]
configs = [
  "ndviet/standalone-chrome:latest", '{"browserName": "chrome"}',
  ....
]

[server]
host = "<node-ip>"
port = 5555

I also ran the selenium-hub using the Docker image you mentioned.

While the WebSocket connection is successful, it seems to close immediately if the Duration is less than 10 seconds. It's not exact, but it appears that only after exceeding about 10 seconds, the connection remains properly open without closing, allowing me to view the screen.

스크린샷 2024-01-08 오후 6 06 13 스크린샷 2024-01-08 오후 6 05 39

The two images were run at different times, so the session IDs are different, but the same issue occurs every time they are executed.

For testing purposes, I used RemoteWebDriver to execute the code and then added a long Thread.sleep in the next line for testing.

@VietND96
Copy link
Member

VietND96 commented Jan 8, 2024

@hil00137, thank you. There is an error message that I could not see in my local while testing noVNC requires a secure context (TLS). Expect crashes!
I saw -v ${PWD}/selenium-http-jdk-client.jar:/opt/selenium/selenium-http-jdk-client.jar \. How about if unset this one?

@diemol
Copy link
Member

diemol commented Jan 8, 2024

@hil00137 you never mentioned you are using the node-docker images. It would be good if you actually share how you are running the Grid.

@hil00137
Copy link
Author

hil00137 commented Jan 9, 2024

@VietND96
Even when I remove the configuration for selenium-http-jdk-client.jar and try again, the WebSocket connects properly after a certain amount of time, just like in my previous attempts.

@hil00137
Copy link
Author

hil00137 commented Jan 9, 2024

@diemol
I didn't mention it in the main text, but I thought the issue with the WebSocket trying to connect to a strange URL was independent of Docker usage.
I am currently setting up a Selenium grid consisting of one selenium-hub and one selenium node-docker, both using Docker. Both are on the same server, but I am accessing them using an external IP, not localhost, to make it easier to separate them when expanding the grid in the future. For the node-docker, I have set it up for Chrome and Edge standalone.

[docker]
configs = [
  "selenium/standalone-chrome:120.0", '{"browserName": "chrome", "browserVersion": "120.0"}',
  "selenium/standalone-edge:120.0", '{"browserName": "MicrosoftEdge", "browserVersion": "120.0"}'
]

[server]
host = "<node-ip>"
port = 5555

@diemol
Copy link
Member

diemol commented Jan 9, 2024

Fixed by #13407

@diemol diemol closed this as completed Jan 9, 2024
Copy link

github-actions bot commented Feb 9, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants