0

This "Session timed out or not found" error has been a curse on my existence. Often it has ended-up being symptomatic of something else, but I'm currently using Selenium with Chromium (by way of Selenoid) in eight different places, and it works flawlessly in seven of them and failing consistently, during every single run, in another and for seemingly no reason:

...
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/opt/obo/virtualenv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Session timed out or not found

I have not yet seen it have anything actually to do with timeouts, but I still doubled or tripled every timeout I could find, and it was still happening. I reduced the amount of data from returned from the Javascript to Python, and it's still happening. I then timed how long it takes for this to occur, when it occurs, and it looks like (0) seconds. There seems to be no documentation of this error out there and very few references in general. So, maybe someone has some advice or can at least describe what causes this, before I have to tear it apart myself?

Dustin Oprea
  • 9,673
  • 13
  • 65
  • 105

4 Answers4

0

Its signal that Selenium Grid instance does not keep session anymore.

Please try running tests without Selenoid, with local grid to see if error persists

Possible issues with Selenoid:

  1. Default session timeout (60 seconds if I'm not mistaken) occurs when time between consecutive calls to that session exceeds timeout setting. The solution is to review tests or extend timeout.

  2. Improper load on Selenoid host (too few CPU or memory or too much instances) leads to struggle for resources and thus Selenoid instance may behave instable. Solutions: fix Selenoid setup

Yevhen B
  • 306
  • 1
  • 4
  • As mentioned, I receive this error after only (0) seconds. It's not a firewall or resource/contention issue (at least not obviously). This also occurred prior to using Selenoid. I moved to Selenoid to eliminate indirect issues like this, but it never resolved this particular issue. I'm not using Grid; I have my own service broker that manages and throttles requests to Selenium. – Dustin Oprea Mar 15 '21 at 19:11
0

Could also be because of missing firewall rules for some page elements (scripts, images and so on). Because of firewall these requests take infinite time to finish and thus your page loads too slowly and finally a timeout occurs.

vania-pooh
  • 2,933
  • 4
  • 24
  • 42
0

This issue seemed to occur every time after I ran through another window with infinite scroll. It infrequently occurred at other times at seemingly-random intervals.

It could be that some sites do something that put the window into a bad state. It could be me not doing something that I'm not aware of that I need to do after doing an infinite scroll.

Either way, I added a contingency to detect that specific exception and message and to just close that window and then open a new one on the next cycle. That completely eliminated this error/symptom and ostensibly prevented it from ever coming back.

Dustin Oprea
  • 9,673
  • 13
  • 65
  • 105
  • It turned out that I had a bug in a retry loop that was exacerbating the problem. If I encountered this error, I'd assume that my window was unhealthy, closed it, and opened a new one. It did this, but I believe the retry-loop that managed this was inadvertently still breaking out of the loop and returning/reraising the original error. I noticed this during a refactor and fixed it, and haven't seen this error since (finally). So, using a new window was definitely the correct solution and worked once my own bug got out of my way. – Dustin Oprea Feb 22 '22 at 19:16
0

I also faced similar issue. Based on my research what I found is as below:

Try to keep Selenoid session less than 100% as per your code. Any session on hold may encounter this issue.

For example:

You have capability to run 10 threads in parallel (default config), try to launch only 8 threads at a time. This will help you to avoid unnecessary failures.

I have handled it in python using pytest-parallel link as below:

pytest --workers 8 --tests-per-worker 1

This will launch 8 sessions at a time with 1 test per worker and your selenoid usage is 80% at a time i.e. less than 100 %

Diptman
  • 374
  • 3
  • 14