title: Selenium standalone in docker compose - killed by OS?
body: <p>I am running an application using docker-compose.
  One of the containers is a <code>selenium/standalone-chrome</code> image. I give is <code>shm_size</code> of 2g. </p>
  
  <p>The application works fine when there is no high load. However, I have noticed that whenever there are concurrent requests to the selenium container (9 concurrent requests on a 8-core machine) Selenium fails silently. It just dies and stays dead. Subsequent request are not handled. There is nothing in the logs. The last message is:</p>
  
  <p><code>17:41:00.083 INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 5da2cd57f4e8e4f80b907564d7352051 (org.openqa.selenium.chrome.ChromeDriverService)</code></p>
  
  <p>I am monitoring the RAM and CPU usage using both <code>docker stats</code> and <code>top</code>. Ram is fine .. about 50% used. Using <code>free -m</code> shows shared memory at about 500m. The 8 cores are taking the load staying at around 80% most of the time. However, whenever the last request arrives - the processes just die out. CPU usage drops. Shared memory does not seem to be released though. </p>
  
  <p>In order to make it work again, I have to restart the application. Otherwise, none of the subsequent requests are received or logged. </p>
  
  <p>I suspect there might me some kind of limitation from the OS on the containers and once they start consuming resources the OS kills them, but to be fair, I have no idea what is going on.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks!</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here is my docker-compose reference</p>
  
  <pre><code>  selenium-chrome:
      image: selenium/standalone-chrome
      privileged: true
      shm_size: 2g
      expose:
        - "4444"
  </code></pre>
  
  <p>This is what my logs look like when it hangs: <a href="https://i.stack.imgur.com/MJnAL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MJnAL.png" alt="enter image description here"></a></p>
  
  <p>And after I kill the docker-compose process and restart it:
  <a href="https://i.stack.imgur.com/5GE5V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5GE5V.png" alt="enter image description here"></a></p>
  
  <p>I have also tested different images. These screenshots are actually with image <code>selenium/standalone-chrome:3.141.59-gold</code>.</p>
  
  <p>One last thing that puzzles me even more - I am using selenium for screenshots, and I have added webhook call in the java code if the process fails. I would expect it to fire if the selenium process dies, however, it seem the java does not consider the selenium connection dead and stays waiting until I <code>docker-compose down</code>. Then all the messages from the webhook are fired.</p>
  
  <p><strong>Update2:</strong>
  Here is what I have tried and I know so far:</p>
  
  <pre><code>1. chrome driver version makes no difference
  2. shm_size increase does not make any difference
  3. jvm memory limit makes no difference - command: ["java", "-Xmx2048m", "-jar", "/opt/selenium/selenium-server-standalone.jar"]
  4. always hangs on the same spot .. 8 concurrent processes on a 8 core machine
  5. once dead, stays dead 
  6. lots of chrome processes hang there - ps -aux | grep chrome 
  6.1 if those processes are killed - sudo kill -9 $(ps aux | grep 'chrome' | awk '{print $2}'), the process does not start again and stays dead.
  7. --no-sandbox option does not help
  8. the java process is alive on the host - telnet ip 4444 -&gt; connects succesfully 
  </code></pre>