diff --git a/CHANGELOG.md b/CHANGELOG.md index 38bc2b3..40a20a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## v3.1.0 (upcoming) +* Kill Chromium processes properly to avoid defunct/zombie processes * Include procps (ps), curl and vim packages in the Docker image ## v3.0.0 (2023/01/04) diff --git a/Dockerfile b/Dockerfile index baac979..b74bb64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,8 @@ RUN dpkg -i /libgl1-mesa-dri.deb \ && dpkg -i /adwaita-icon-theme.deb \ # Install dependencies && apt-get update \ - && apt-get install -y --no-install-recommends chromium chromium-common chromium-driver xvfb procps curl vim \ + && apt-get install -y --no-install-recommends chromium chromium-common chromium-driver xvfb dumb-init \ + procps curl vim \ # Remove temporary files and hardware decoding libraries && rm -rf /var/lib/apt/lists/* \ && rm -f /usr/lib/x86_64-linux-gnu/libmfxhw* \ @@ -52,6 +53,9 @@ COPY package.json ../ EXPOSE 8191 +# dumb-init avoids zombie chromium processes +ENTRYPOINT ["/usr/bin/dumb-init", "--"] + CMD ["/usr/local/bin/python", "-u", "/app/flaresolverr.py"] # Local build diff --git a/src/undetected_chromedriver/__init__.py b/src/undetected_chromedriver/__init__.py index 8e020fb..52e4aae 100644 --- a/src/undetected_chromedriver/__init__.py +++ b/src/undetected_chromedriver/__init__.py @@ -599,7 +599,8 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver): def quit(self): logger.debug("closing webdriver") if hasattr(self, "service") and getattr(self.service, "process", None): - self.service.process.kill() + self.service.process.terminate() + self.service.process.wait(5) try: if self.reactor and isinstance(self.reactor, Reactor): logger.debug("shutting down reactor") diff --git a/src/undetected_chromedriver/dprocess.py b/src/undetected_chromedriver/dprocess.py index c934392..ae88c82 100644 --- a/src/undetected_chromedriver/dprocess.py +++ b/src/undetected_chromedriver/dprocess.py @@ -27,12 +27,14 @@ def start_detached(executable, *args): reader, writer = multiprocessing.Pipe(False) # do not keep reference - multiprocessing.Process( + process = multiprocessing.Process( target=_start_detached, args=(executable, *args), kwargs={"writer": writer}, daemon=True, - ).start() + ) + process.start() + process.join() # receive pid from pipe pid = reader.recv() REGISTERED.append(pid)