Skip to content

Commit

Permalink
Kill Chromium processes properly to avoid defunct/zombie processes
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang committed Jan 6, 2023
1 parent 4807e9d commit 7d84f1b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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* \
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/undetected_chromedriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ def start_session(self, capabilities=None, browser_profile=None):
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")
Expand Down
6 changes: 4 additions & 2 deletions src/undetected_chromedriver/dprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7d84f1b

Please sign in to comment.