selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: NoSuchSessionError: invalid session id

Open davideDimolaFincons opened this issue 1 year ago • 4 comments

What happened?

I everyone,

we've developer son e2e tests using selenium for NodeJS, but we're experiencing some random errors while the test is being executed. Once the test has already started, in the middle of some kind of action with the browser, the test fails with this error:

NoSuchSessionError: invalid session id
 at Object.throwDecodedError (/node_modules/seleniumwebdriver/lib/error.js:524:15)
 at parseHttpResponse (/node_modules/selenium-webdriver/lib/
http.js:605:13)
 at Executor.execute (/node_modules/selenium-webdriver/lib/
http.js:533:28)
 at processTicksAndRejections (node:internal/process/
task_queues:95:5)
 at Driver.execute (/node_modules/selenium-webdriver/lib/
webdriver.js:746:17)

Seems like the session is somehow killed or not more available (the test starts without problem, the browser get open, the error occurs in the middle of the test logic). The only "strange" thing that we've noticed is this log in the test related node:

14:28:40.312 INFO [SessionSlot.stop] - Stopping session 444f353bc946a834034f68a2930bfe40
14:28:43.275 INFO [LocalNode.newSession] - Session created by the Node. Id: ac3fd556e00dc724fb6d1bec66abccfc, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 121.0.6167.87, chrome: {chromedriverVersion: 121.0.6167.85 (3f98d690ad7e..., userDataDir: C:\Users\dimolad\AppData\Lo...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:27201}, goog:loggingPrefs: {performance: ALL}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: Windows XP, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://10.137.12.8:4444/sessi..., se:cdpVersion: 121.0.6167.87, 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}
14:29:26.302 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "9b765eced5ee39751103dad4d1835b50","eventTime": 1707139766302263500,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:33.184 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "6b86dd029d4d4c1e97493128841fdbab","eventTime": 1707139773184187400,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:39.490 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "95e8081234c2fc5095fc04e0e323c918","eventTime": 1707139779489566900,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:45.156 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "30f5762d46cfb979f5ac77f7751fc018","eventTime": 1707139785154286700,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:32:03.615 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "a56bba3ca1e356bd9a2826566c97bf5b","eventTime": 1707139923615431100,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.232 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "037da9106291a16c7aa6c369fc385be8","eventTime": 1707140025243745000,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "2","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fwindow","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.327 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "fc5d9e319e7ee7bf33fd563e872e1029","eventTime": 1707140025313358000,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "GET","http.request_content_length": "0","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fscreenshot","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.406 INFO [SessionSlot.stop] - Stopping session ac3fd556e00dc724fb6d1bec66abccfc

It seems related somehow to screenshots, which we use in the test, but is not clear what is the issue from hub/nodes logs.

Here some info about the Selenium grid host:

  • virtual machine
  • windows server 2022 (v. 21H2)
  • 4 virtual CPUs
  • 8GBs RAM
  • selenium grid configured with 2 nodes (nothing special here)
  • Selenium Hub 4.16.1 (revision 9b4c83354e)

Selenium grid is started by a simple .bat file (launched manually), the code is the sequent:

echo Starting selenium components

start "Selenium HUB" java -jar .\selenium-server.jar hub --tracing true --log "hub.log" --log-level "CONFIG"
start "Selenium node 1" java -jar .\selenium-server.jar node --port 5555 --selenium-manager true --log "node_1.log" --log-level "CONFIG"
start "Selenium node 2" java -jar .\selenium-server.jar node --port 5556 --selenium-manager true --log "node_2.log" --log-level "CONFIG"

:CheckProcesses
tasklist /FI "IMAGENAME eq java.exe" | find /i "java.exe"
if %errorlevel% == 0 (
    timeout /t 5 /nobreak > NUL
    goto :CheckProcesses
)

echo All Java processes have completed.

How can we reproduce the issue?

(still something related to the environment?)

Relevant log output

14:28:40.312 INFO [SessionSlot.stop] - Stopping session 444f353bc946a834034f68a2930bfe40
14:28:43.275 INFO [LocalNode.newSession] - Session created by the Node. Id: ac3fd556e00dc724fb6d1bec66abccfc, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 121.0.6167.87, chrome: {chromedriverVersion: 121.0.6167.85 (3f98d690ad7e..., userDataDir: C:\Users\dimolad\AppData\Lo...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:27201}, goog:loggingPrefs: {performance: ALL}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: Windows XP, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://10.137.12.8:4444/sessi..., se:cdpVersion: 121.0.6167.87, 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}
14:29:26.302 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "9b765eced5ee39751103dad4d1835b50","eventTime": 1707139766302263500,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:33.184 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "6b86dd029d4d4c1e97493128841fdbab","eventTime": 1707139773184187400,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:39.490 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "95e8081234c2fc5095fc04e0e323c918","eventTime": 1707139779489566900,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:29:45.156 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "30f5762d46cfb979f5ac77f7751fc018","eventTime": 1707139785154286700,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:32:03.615 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "a56bba3ca1e356bd9a2826566c97bf5b","eventTime": 1707139923615431100,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "6486","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fexecute\u002fsync","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.232 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "037da9106291a16c7aa6c369fc385be8","eventTime": 1707140025243745000,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "POST","http.request_content_length": "2","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fwindow","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.327 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "fc5d9e319e7ee7bf33fd563e872e1029","eventTime": 1707140025313358000,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.remote.http.Route$PredicatedRoute","http.host": "10.137.12.8:5556","http.method": "GET","http.request_content_length": "0","http.scheme": "HTTP","http.status_code": 404,"http.target": "\u002fsession\u002fac3fd556e00dc724fb6d1bec66abccfc\u002fscreenshot","http.user_agent": "selenium\u002f4.17.0 (js linux)"}}

14:33:45.406 INFO [SessionSlot.stop] - Stopping session ac3fd556e00dc724fb6d1bec66abccfc

Operating System

Windows Server 2022

Selenium version

NodeJS 18.x.x

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

Chrome 121.0.6167.87

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

ChromeDriver: 121.0.6167.85

Are you using Selenium Grid?

4.16.1

davideDimolaFincons avatar Feb 05 '24 14:02 davideDimolaFincons

@davideDimolaFincons, 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!

github-actions[bot] avatar Feb 05 '24 14:02 github-actions[bot]

What is your code. You appear to be quitting the session and then trying to access it again. It's JS, are you sure you are synchronizing this part correctly?

titusfortner avatar Feb 05 '24 17:02 titusfortner

Yes, the session is closed only in the afterEach() lifecycle of Jest, so there's no way this can happened during the test. By the way, from further analisys it seems that the session get expired always at the same point, is there any timeout (on nodes, hub or whatever) that could invalidate the actual session?

davideDimolaFincons avatar Feb 15 '24 15:02 davideDimolaFincons

There is a session timeout, that kicks in when you leave the session idle and then stops the session.

diemol avatar Feb 15 '24 15:02 diemol

I've increased the session timeout by starting nodes and hub in this way (windows machine):

start "Selenium HUB" java -jar .\selenium-server.jar hub --session-request-timeout 600 --log "hub.log" --log-level "CONFIG"
start "Selenium node 1" java -jar .\selenium-server.jar node --port 5555 --session-timeout 600 --selenium-manager true --log "node_1.log" --log-level "CONFIG"
start "Selenium node 2" java -jar .\selenium-server.jar node --port 5556 --session-timeout 600 --selenium-manager true --log "node_2.log" --log-level "CONFIG"

These are logs from both hub and node, as you can see selenium, after few warnings, decide to delete the session after ~4'30", while my test crashes after ~4'55" (which make me think that the session has been shut down while there's still interactions with the browser)

image

As documentation says, --session-request-timeout and --session-timeout are expressed in seconds, is it correct or are they milliseconds?

davideDimolaFincons avatar Feb 22 '24 09:02 davideDimolaFincons

In seconds.

What do the warnings say?

diemol avatar Feb 22 '24 09:02 diemol

In seconds.

What do the warnings say?

You can check them in the first comment of mine in this issue

davideDimolaFincons avatar Feb 22 '24 09:02 davideDimolaFincons

It looks like you are trying to execute JS in the browser, and it returns a 404. For some reason, the session timeout kicks off and it ends.

I would need a test script to reproduce the issue so I can look into it.

diemol avatar Feb 22 '24 09:02 diemol

It looks like you are trying to execute JS in the browser, and it returns a 404. For some reason, the session timeout kicks off and it ends.

I would need a test script to reproduce the issue so I can look into it.

I'm afraid this is quite impossibile, we're testing a web application accessible only by customer VPN

davideDimolaFincons avatar Feb 22 '24 10:02 davideDimolaFincons

Hi, @davideDimolaFincons. Please follow the issue template, we need more information to reproduce the issue.

Either a complete code snippet and URL/HTML (if more than one file is needed, provide a GitHub repo and instructions to run the code), the specific versions used, or a more detailed description to help us understand the issue.

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

Reply to this issue when all information is provided, thank you.

github-actions[bot] avatar Feb 22 '24 10:02 github-actions[bot]

Note: If you cannot share your code and URL/HTML, any complete code snippet and URL/HTML that reproduces the issue is good enough.

diemol avatar Feb 22 '24 10:02 diemol

It doesn't look like the nodes are getting connected to the hub? What is the initialization code? Why not run one server in standalone mode if it is on the same computer?

titusfortner avatar Mar 08 '24 21:03 titusfortner

This issue was closed because we did not receive any additional information after 14 days.

github-actions[bot] avatar Mar 23 '24 10:03 github-actions[bot]

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

github-actions[bot] avatar Apr 22 '24 22:04 github-actions[bot]