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]: docker-compose-v3-dynamic-grid set SE_NODE_SESSION_TIMEOUT not effect #1824

Closed
wuyue92tree opened this issue Apr 13, 2023 · 8 comments · Fixed by #2044
Closed

Comments

@wuyue92tree
Copy link

wuyue92tree commented Apr 13, 2023

What happened?

When I set SE_NODE_SESSION_TIMEOUT to 600 , It still closed after 300 second.

Command used to start Selenium Grid with Docker

My docker-compose.yaml

version: "3"
services:
  node-docker:
    shm_size: 2gb
    image: selenium/node-docker:4.8.1-20230306
    volumes:
      - ./assets:/opt/selenium/assets
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444/
      - SE_NODE_SESSION_TIMEOUT=600
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000

  selenium-hub:
    image: selenium/hub:4.8.1-20230306
    container_name: selenium-hub
    environment:
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000
    volumes:
      - ./config.toml:/opt/selenium/config.toml
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"

but when I set SE_OPTS=--session-timeout 600, it's work fine.

version: "3"
services:
  node-docker:
    shm_size: 2gb
    image: selenium/node-docker:4.8.1-20230306
    volumes:
      - ./assets:/opt/selenium/assets
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444/
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000
      - SE_OPTS=--session-timeout 600

  selenium-hub:
    image: selenium/hub:4.8.1-20230306
    container_name: selenium-hub
    environment:
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000
    volumes:
      - ./config.toml:/opt/selenium/config.toml
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"


### Relevant log output

```shell
session closed after 300 second

Operating System

Centos7

Docker Selenium version (tag)

4.8.1-20230306

@github-actions
Copy link

@wuyue92tree, 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 Apr 13, 2023

Can you please update to the latest image and then share the logs where we can see that the timeout is not respected? Also please share a script we can use to reproduce the issue.

@wuyue92tree
Copy link
Author

Can you please update to the latest image and then share the logs where we can see that the timeout is not respected? Also please share a script we can use to reproduce the issue.

Thanks for reply. Like you said, I update to the latest image, but issue still here.

docker-compose.yaml and config.toml

version: "3"
services:
  node-docker:
    shm_size: 2gb
    image: selenium/node-docker:4.8.3-20230404
    volumes:
      - ./assets:/opt/selenium/assets
      - ./config.toml:/opt/bin/config.toml
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
      - SE_NODE_GRID_URL=http://localhost:4444/
      - SE_NODE_SESSION_TIMEOUT=600
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000
      #- SE_OPTS=--session-timeout 3600

  selenium-hub:
    image: selenium/hub:4.8.3-20230404
    container_name: selenium-hub
    environment:
      - JAVA_OPTS=-Djdk.httpclient.websocket.intermediateBufferSize=3000000
    volumes:
      - ./config.toml:/opt/selenium/config.toml
    ports:
      - "4442:4442"
      - "4443:4443"
      - "4444:4444"
 
[docker]
# Configs have a mapping between the Docker image to use and the capabilities that need to be matched to
# start a container with the given image.
# configs = [
#     "selenium/standalone-firefox:4.8.1-20230306", "{\"browserName\": \"firefox\"}",
#     "selenium/standalone-chrome:4.8.1-20230306", "{\"browserName\": \"chrome\"}",
#     "selenium/standalone-edge:4.8.1-20230306", "{\"browserName\": \"MicrosoftEdge\"}"
#     ]

configs = [
    "selenium/standalone-chrome:4.8.3-20230404", "{\"browserName\": \"chrome\"}"
    ]

# URL for connecting to the docker daemon
# Most simple approach, leave it as http://127.0.0.1:2375, and mount /var/run/docker.sock.
# 127.0.0.1 is used because interally the container uses socat when /var/run/docker.sock is mounted 
# If var/run/docker.sock is not mounted: 
# Windows: make sure Docker Desktop exposes the daemon via tcp, and use http://host.docker.internal:2375.
# macOS: install socat and run the following command, socat -4 TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock,
# then use http://host.docker.internal:2375.
# Linux: varies from machine to machine, please mount /var/run/docker.sock. If this does not work, please create an issue.
url = "http://127.0.0.1:2375"
# Docker image used for video recording
video-image = "selenium/video:ffmpeg-4.3.1-20230404"

# Uncomment the following section if you are running the node on a separate VM
# Fill out the placeholders with appropriate values
#[server]
#host = <ip-from-node-machine>
#port = <port-from-node-machine>
#

container & images version and logger

[work()@tjtx167-200-143 selenium]$ docker ps
CONTAINER ID   IMAGE                                 COMMAND                  CREATED              STATUS              PORTS                              NAMES
9ceaa8150e67   1ac7ccac8ba0                          "/opt/bin/entry_poin…"   12 seconds ago       Up 11 seconds       4444/tcp, 5900/tcp                 loving_keldysh
91b4ff9810ef   selenium/node-docker:4.8.3-20230404   "/opt/bin/entry_poin…"   About a minute ago   Up About a minute   4444/tcp                           selenium-node-docker-1
0858898210ae   selenium/hub:4.8.3-20230404           "/opt/bin/entry_poin…"   About a minute ago   Up About a minute   0.0.0.0:4442-4444->4442-4444/tcp   selenium-hub
e555332390a8   scrapinghub/splash                    "python3 /app/bin/sp…"   5 weeks ago          Up 5 weeks          0.0.0.0:8050->8050/tcp             splash
[work()@tjtx167-200-143 selenium]$ docker images |grep 4.8.3-20230404
selenium/standalone-chrome    4.8.3-20230404          1ac7ccac8ba0   9 days ago     1.3GB
selenium/node-docker          4.8.3-20230404          29fb467c80ed   9 days ago     421MB
selenium/hub                  4.8.3-20230404          41f0baa95233   9 days ago     420MB
[work()@tjtx167-200-143 selenium]$ docker logs -f 9ceaa8150e67
2023-04-13 07:20:42,094 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2023-04-13 07:20:42,098 INFO RPC interface 'supervisor' initialized
2023-04-13 07:20:42,098 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2023-04-13 07:20:42,099 INFO supervisord started with pid 9
2023-04-13 07:20:43,102 INFO spawned: 'xvfb' with pid 11
2023-04-13 07:20:43,105 INFO spawned: 'vnc' with pid 12
2023-04-13 07:20:43,107 INFO spawned: 'novnc' with pid 13
2023-04-13 07:20:43,110 INFO spawned: 'selenium-standalone' with pid 14
2023-04-13 07:20:43,137 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2023-04-13 07:20:43,137 INFO success: vnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2023-04-13 07:20:43,137 INFO success: novnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2023-04-13 07:20:43,137 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
Selenium Grid Standalone configuration: 
[network]
relax-checks = true

[node]
grid-url = "http://localhost:4444/"
session-timeout = "600"
override-max-sessions = false
detect-drivers = false
drain-after-session-count = 0
max-sessions = 1

[[node.driver-configuration]]
display-name = "chrome"
stereotype = '{"browserName": "chrome", "browserVersion": "111.0", "platformName": "Linux"}'
max-sessions = 1

Starting Selenium Grid Standalone...
Tracing is disabled
07:20:43.789 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
07:20:43.796 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
07:20:44.699 INFO [NodeOptions.getSessionFactories] - Detected 4 available processors
07:20:44.785 INFO [NodeOptions.report] - Adding chrome for {"browserVersion": "111.0","se:noVncPort": 7900,"browserName": "chrome","platformName": "LINUX","se:vncEnabled": true} 1 times (Host)
07:20:44.815 INFO [Node.<init>] - Binding additional locator mechanisms: relative
07:20:44.864 INFO [GridModel.setAvailability] - Switching Node b2a6fc0a-60c8-4d83-a220-f7446e5eaeb0 (uri: http://172.18.0.4:4444) from DOWN to UP
07:20:44.865 INFO [LocalDistributor.add] - Added node b2a6fc0a-60c8-4d83-a220-f7446e5eaeb0 at http://172.18.0.4:4444. Health check every 120s
07:20:45.061 INFO [Standalone.execute] - Started Selenium Standalone 4.8.3 (revision b19b418e60): http://172.18.0.4:4444
07:20:45.950 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-field-trial-config, --disable-background-networ..., --enable-features=NetworkSe..., --disable-background-timer-..., --disable-backgrounding-occ..., --disable-back-forward-cache, --disable-breakpad, --disable-client-side-phish..., --disable-component-extensi..., --disable-default-apps, --disable-dev-shm-usage, --disable-extensions, --disable-features=Improved..., --allow-pre-commit-input, --disable-hang-monitor, --disable-ipc-flooding-prot..., --disable-popup-blocking, --disable-prompt-on-repost, --disable-renderer-backgrou..., --disable-sync, --force-color-profile=srgb, --metrics-recording-only, --no-first-run, --enable-automation, --password-store=basic, --use-mock-keychain, --no-service-autorun, --export-tagged-pdf, --no-sandbox, --remote-debugging-port=0]}}]
Starting ChromeDriver 111.0.5563.64 (c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995}) on port 9480
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1681370446.003][SEVERE]: bind() failed: Cannot assign requested address (99)
ChromeDriver was started successfully.
07:20:47.181 INFO [LocalNode.newSession] - Session created by the Node. Id: 265dc42b486d5e842457f0768ab18221, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 111.0.5563.146, chrome: {chromedriverVersion: 111.0.5563.64 (c710e93d5b63..., userDataDir: /tmp/.com.google.Chrome.9Kcx59}, goog:chromeOptions: {debuggerAddress: localhost:37173}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:cdp: http://localhost:37173, se:cdpVersion: 111.0.5563.146, se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.4:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
07:20:47.189 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 265dc42b486d5e842457f0768ab18221 
 Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 111.0.5563.146, chrome: {chromedriverVersion: 111.0.5563.64 (c710e93d5b63..., userDataDir: /tmp/.com.google.Chrome.9Kcx59}, goog:chromeOptions: {debuggerAddress: localhost:37173}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: LINUX, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://localhost:4444/session..., se:cdpVersion: 111.0.5563.146, se:vnc: ws://localhost:4444/session..., se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.4:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
07:20:47.845 INFO [ProxyNodeWebsockets.apply] - Matched endpoint where CDP connection is being forwarded
07:20:47.866 INFO [ProxyNodeWebsockets.createWsEndPoint] - Establishing connection to ws://localhost:37173/devtools/browser/309cea36-40d1-4b16-a92d-77a97ed97762
07:25:53.941 WARN [DefaultChannelPipeline.onUnhandledInboundException] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
org.openqa.selenium.WebDriverException: java.lang.IllegalArgumentException: statusCode
Build info: version: '4.8.3', revision: 'b19b418e60'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '4.18.20-2.el7.wuba.lp.x86_64', java.version: '11.0.18'
Driver info: driver.version: unknown
  at org.openqa.selenium.remote.http.jdk.JdkHttpClient$5.send(JdkHttpClient.java:239)
  at org.openqa.selenium.netty.server.WebSocketMessageHandler.lambda$channelRead0$0(WebSocketMessageHandler.java:47)
  at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
  at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
  at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
  at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalArgumentException: statusCode
  at java.net.http/jdk.internal.net.http.websocket.WebSocketImpl.sendClose(WebSocketImpl.java:301)
  at org.openqa.selenium.remote.http.jdk.JdkHttpClient$5.lambda$send$2(JdkHttpClient.java:222)
  at org.openqa.selenium.remote.http.jdk.JdkHttpClient$5.send(JdkHttpClient.java:229)
  ... 9 more
07:25:53.997 INFO [LocalSessionMap.lambda$new$0] - Deleted session from local Session Map, Id: 265dc42b486d5e842457f0768ab18221
07:25:54.000 INFO [GridModel.release] - Releasing slot for session id 265dc42b486d5e842457f0768ab18221
07:25:54.002 INFO [SessionSlot.stop] - Stopping session 265dc42b486d5e842457f0768ab18221
Trapped SIGTERM/SIGINT/x so shutting down supervisord...
2023-04-13 07:25:55,005 WARN received SIGTERM indicating exit request
2023-04-13 07:25:55,005 INFO waiting for xvfb, vnc, novnc, selenium-standalone to die
2023-04-13 07:25:55,349 INFO stopped: selenium-standalone (terminated by SIGTERM)
2023-04-13 07:25:56,351 INFO stopped: novnc (terminated by SIGTERM)
2023-04-13 07:25:57,353 INFO stopped: vnc (terminated by SIGTERM)
2023-04-13 07:25:58,355 INFO stopped: xvfb (terminated by SIGTERM)
Shutdown complete

Test script, I use playwright-python

import os

from playwright.sync_api import sync_playwright


# pip install playwright==1.23.0

def run():
    # https://playwright.dev/docs/selenium-grid#connecting-playwright-to-selenium-grid
    os.environ['SELENIUM_REMOTE_URL'] = 'http://selenium:4444'  # selenium hub url
    os.environ['DEBUG'] = 'pw:browser*'
    with sync_playwright() as p:

        browser = p.chromium.launch(headless=False, channel='chrome')
        context = browser.new_context(
            user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
                       ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
        )
        page = context.new_page()
        try:
            # skip webdriver check
            page.add_init_script("""
                navigator.webdriver = false
                Object.defineProperty (navigator, 'webdriver', {
                    get: () => false
                })
            """)
            page.goto('https://www.baidu.com/')
            while True:
                page.wait_for_timeout(10000)
                # reload page every 10 seconds
                page.reload()
        except Exception as e:
            print(e)
        finally:
            page.close()
            context.close()
            browser.close()


if __name__ == '__main__':
    run()

@wuyue92tree
Copy link
Author

Another strange behavior is that,when the SE_NODE_SESSION_TIMEOUT set to 60(less than 300). It's work fine

@jamesmortensen
Copy link
Member

@wuyue92tree Thanks for including the scripts to replicate the issue. We'll dig in as soon as we can.

@bluejay1216
Copy link

I ran into the same issue when running Selenium Node Docker (node-docker:4.12.1-20230912) with the -e SE_NODE_SESSION_TIMEOUT option through the environment variable. It can't be set to anything greater than the default timeout value as @wuyue92tree mentioned. The current workaround is to set the timeout value through -e SE_OPTS option as mentioned in the description.

@jamesmortensen
Copy link
Member

If one of you wants to open a pull request on this, it would be greatly appreciated. For now, it looks like we have a workaround.

VietND96 added a commit to NDViet/docker-selenium that referenced this issue Dec 2, 2023
…effect

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
VietND96 added a commit to NDViet/docker-selenium that referenced this issue Dec 2, 2023
…effect

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
VietND96 added a commit to NDViet/docker-selenium that referenced this issue Dec 2, 2023
…effect

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
@VietND96 VietND96 linked a pull request Dec 2, 2023 that will close this issue
8 tasks
VietND96 added a commit that referenced this issue Dec 3, 2023
)

* bug(#1824): Container ENV SE_NODE_SESSION_TIMEOUT not take effect

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>

* Update helm-chart-test.yml for SNAPSHOT CI build

* Update helm-chart-test.yml for SNAPSHOT CI build

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>

* Revert test

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>

---------

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
Copy link

github-actions bot commented Jan 2, 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 Jan 2, 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