title: Connection refused (os error 111) after few successful Selenium Geckodriver tasks (Python)
body: <p>OS: Ubuntu 20.04 no GUI.</p>
  <p>I'm doing a quite simple task there in headless mode:</p>
  <ol>
  <li>Installing and enabling firefox addon.</li>
  <li>Navigating to about:debugging#/runtime/this-firefox and getting addon's uuid.</li>
  </ol>
  <p>The problem is that after a few successful .py script completions, next ones just hang and return Connection refused (os error 111) error. After that I have to reboot the server which fix issue for a few .py script launches only.</p>
  <p>My code:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.firefox.options import Options as FirefoxOptions
  from selenium.webdriver import FirefoxProfile
  import time
  
  ff_options = FirefoxOptions()
  
  user_agent = &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36&quot;
  
  ff_options.add_argument('-headless')
  ff_options.add_argument(f'user-agent={user_agent}')
  ff_options.add_argument('--disable-dev-shm-usage')
  ff_options.add_argument('--no-sandbox')
  ff_options.add_argument(&quot;--window-size=1920,1080&quot;)
  ff_options.add_argument('--ignore-certificate-errors')
  ff_options.add_argument('--allow-running-insecure-content')
  ff_options.add_argument(&quot;--proxy-server='direct://'&quot;)
  ff_options.add_argument(&quot;--proxy-bypass-list=*&quot;)
  ff_options.add_argument(&quot;--start-maximized&quot;)
  ff_options.add_argument('--disable-gpu')
  ff_options.add_argument('--disable-setuid-sandbox')
  
  buster = &quot;/root/my_simple_extension.xpi&quot;
  
  driver = webdriver.Firefox(executable_path='/usr/local/share/geckodriver', options=ff_options)
  driver.install_addon(buster, temporary=True)
  driver.profile = webdriver.FirefoxProfile()
  driver.profile.add_extension(buster)
  driver.profile.set_preference(&quot;security.fileuri.strict_origin_policy&quot;, False)
  driver.profile.update_preferences()
  
  driver.get(&quot;about:debugging#/runtime/this-firefox&quot;)
  
  time.sleep(1)
  
  parent1 = driver.find_element_by_xpath('(//div[@class=&quot;fieldpair&quot;])[position()=3]')
  uuid = parent1.text.splitlines()[1]
  
  driver.get('moz-extension://{}/home.html'.format(uuid))
  time.sleep(1)
  print(driver.page_source)
  driver.quit()
  </code></pre>
  <p>geckodriver.log</p>
  <pre><code>1632303683203   geckodriver INFO    Listening on 127.0.0.1:45055
  1632303684204   mozrunner::runner   INFO    Running command: &quot;/usr/bin/firefox&quot; &quot;--marionette&quot; &quot;-headless&quot; &quot;user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36&quot; &quot;--disable-dev-shm-usage&quot; &quot;--no-sandbox&quot; &quot;--window-size=1920,1080&quot; &quot;--ignore-certificate-errors&quot; &quot;--allow-running-insecure-content&quot; &quot;--proxy-server=\'direct://\'&quot; &quot;--proxy-bypass-list=*&quot; &quot;--start-maximized&quot; &quot;--disable-gpu&quot; &quot;--disable-setuid-sandbox&quot; &quot;-no-remote&quot; &quot;-profile&quot; &quot;/tmp/rust_mozprofilexOejpk&quot;
  *** You are running in headless mode.
  [GFX1-]: glxtest: Unable to open a connection to the X server
  [GFX1-]: glxtest: libEGL missing
  1632303684813   Marionette  INFO    Marionette enabled
  [GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
  console.warn: SearchSettings: &quot;get: No settings file exists, new profile?&quot; (new NotFoundError(&quot;Could not open the file at /tmp/rust_mozprofilexOejpk/search.json.mozlz4&quot;, (void 0)))
  1632303687471   Marionette  INFO    Listening on port 42933
  1632303687541   RemoteAgent WARN    TLS certificate errors will be ignored for this session
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/background-8.js, line 17: asm.js type error: expecting argument type declaration for 'e' of the form 'arg = arg|0' or 'arg = +arg' or 'arg = fround(arg)'
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
  1632303696737   Marionette  INFO    Stopped listening on port 42933
  Port.onMessage event fired while context is inactive.
  Port.onMessage event fired while context is inactive.
  Port.onMessage event fired while context is inactive.
  JavaScript error: resource:///modules/Interactions.jsm, line 230: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIUserIdleService.removeIdleObserver]
  </code></pre>