New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Docker image says "Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket" but then after 5 minutes of processing, it finally works? #11900
Comments
This issue was not reproducible. Please check that your example runs locally and the following:
Once the above checks are satisfied, please edit your issue with the changes and we will |
What do I have to do to get the I cache the puppeteer My latest # base image has a lot of unrelated CLI tools installed, based on ubuntu:noble
FROM --platform=linux/amd64 ghcr.io/myorg/mybaseimage:latest
ENV NODE_ENV development
RUN mkdir -p /home/app
WORKDIR /home/app
ENV PORT 8080
COPY *.yaml ./
COPY *.json ./
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Commenting this back in causes it to fully fail I think.
# ENV DBUS_SESSION_BUS_ADDRESS autolaunch:
RUN pnpm install
# && groupadd -r app && useradd -r -g app -G audio,video app \
# && mkdir -p /home/app/Downloads \
# && chown -R app:app /home/app \
# && chown -R app:app /tmp
# USER app
COPY code/ code
RUN pnpm make
EXPOSE ${PORT}
CMD [ "sh", "-c", "pnpm host"] |
dbus should not be required (it works locally with the same docker image, right?) but you can configure dbus in the following way https://github.com/web-platform-tests/wpt/pull/42241/files How fast is the disk on this environment? It looks like launching chrome is slow there and you can probably reproduce the slowness without using Puppeteer. I don't think this is Puppeteer's bug: Puppeteer only can connect to the browser once "DevTools listening on ..." is printed. |
@OrKoN correct, I can run with same docker image locally on my Mac M3. I was going to try this https://stackoverflow.com/questions/42898262/run-dbus-daemon-inside-docker-container but unless you say it's unnecessary. The disk is fast, it writes 5mb files in an instant, but for some reason puppeteer is slow. I would call this a bug because puppeteer isn't working correctly in this environment. |
@OrKoN as you can see from my # Commenting this back in causes it to fully fail I think.
ENV DBUS_SESSION_BUS_ADDRESS autolaunch: |
you also need to install dbus and start the dbus service. |
@OrKoN how do I do that? And why would it fail at first, then work 5 minutes later? |
@OrKoN how do I do this for pnpm with the custom
|
for |
For the sandbox,
I don't think it is part of the regular Chrome so you need to install the version that comes with Puppeteer. |
@OrKoN can you share the full set of commands that will get it fully working with So you're saying I don't need this anymore? RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* What about these, do I need the user and dbus stuff? RUN apt-get install -y dbus
RUN dbus-daemon --system
RUN pnpm install && groupadd -r app && useradd -r -g app -G audio,video app \
&& mkdir -p /home/app/Downloads \
&& chown -R app:app /home/app \
&& chown -R app:app /tmp Nice! |
@OrKoN here is the final dockerfile I am trying, does it look correct? FROM --platform=linux/amd64 ghcr.io/myorg/mybase:latest
ENV NODE_ENV development
RUN mkdir -p /home/app
WORKDIR /home/app
ENV PORT 8080
COPY *.yaml ./
COPY *.json ./
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
ENV DBUS_SESSION_BUS_ADDRESS autolaunch:
# RUN sysctl -w kernel.unprivileged_userns_clone=1
RUN apt-get install -y dbus
RUN dbus-daemon --system
ENV DBUS_SESSION_BUS_ADDRESS autolaunch:
RUN pnpm install
# cd to Puppeteer cache directory (adjust the path if using a different cache directory).
RUN cd ~/.cache/puppeteer/chrome && cd $(ls | grep linux-*) && cd chrome-linux64 \
&& chown root:root chrome_sandbox \
&& chmod 4755 chrome_sandbox \
# copy sandbox executable to a shared location
&& cp -p chrome_sandbox /usr/bin/chrome-devel-sandbox
# export CHROME_DEVEL_SANDBOX env variable
ENV CHROME_DEVEL_SANDBOX /usr/bin/chrome-devel-sandbox
RUN groupadd -r app && useradd -r -g app -G audio,video app \
&& mkdir -p /home/app/Downloads \
&& chown -R app:app /home/app \
&& chown -R app:app /tmp
USER app
COPY code/ code
RUN pnpm make
ENV NODE_ENV production
EXPOSE ${PORT}
CMD [ "sh", "-c", "pnpm host"] P.S., I am still getting this, even locally:
That occurs after 1 invocation of |
@OrKoN I am still setting the
Should I change that |
cc @OrKoN https://www.reddit.com/r/linuxquestions/comments/1aq6826/how_to_start_dbus_on_dockerlinux_failed_to/ If you know how to get dbus working, that would be great. |
I added some logs to
Here's what I see in production, need to add more thorough logs:
So it hangs at this line:
That goes to this puppeteer/packages/browsers/src/launch.ts Lines 355 to 416 in 6cd0ce7
@OrKoN Why would that readline thing be causing slowness on Docker perhaps, any ideas? That is waiting for the chrome executable to return results... |
@lancejpollard I do not think readline is slow, I think the browser process is slow to start so it prints the line late and Puppeteer has to wait for that before it can do anything. The slow startup usually comes from the slow disk, not enough CPU or not enough memory. You could also try the headless: 'shell' mode which is technically not Chrome but a similar more light-weight browser implementation. |
@OrKoN FYI for future reference, the slowness was b/c I was running puppeteer "in the background" on Google Cloud Run, which is basically disabled on Cloud Run by default, see https://www.reddit.com/r/googlecloud/comments/1apcpvr/comment/kqghdoa/?utm_source=share&utm_medium=web2x&context=3 |
@lancejpollard oh wow, I was not aware that Cloud Run does that. I though it is just a server. Would you like to open a PR to add a line to troubleshooting.md about that? |
Minimal, reproducible example
Error string
Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket
Bug behavior
Background
I've been trying to convert HTML to PDF using Puppeteer 22.0.0 on an ubuntu:noble Docker image hosted on Google Cloud Run. Finally it is starting to work (even though I have to use those insecure
--no-sandbox
permissions). But it takes about 5 minutes for the request to complete, first showing that error above, then a few more errors, before it finally works. Everything works fine and fast locally when using against the Docker image locally.Here are the relevant logs from my Google Cloud Run:
Expectation
It should work instantly when called from the REST API I'm using. The REST API logs appear instantly, the puppeteer stuff takes 2-5+ minutes to run.
Reality
It takes a long time to finally process. I had to boost my Google Cloud Run machine size to 8GB RAM and 4 CPU, and choose the "2nd generation" machine which is probably a lot more expensive.
Puppeteer configuration file (if used)
None
Puppeteer version
22.0.0
Node version
20.11.0
Package manager
pnpm
Package manager version
8.15.1
Operating system
Linux
The text was updated successfully, but these errors were encountered: