puppeteer: [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?
Minimal, reproducible example
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--user-data-dir=/tmp',
],
timeout: 0,
executablePath: '/usr/bin/google-chrome',
});
const page = await browser.newPage();
await page.goto('https://google.com');
await page.screenshot({ path: 'google.png' });
await browser.close();
})();
Error string
Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket
Bug behavior
- Flaky
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:
puppeteer:browsers:launcher Launching /usr/bin/google-chrome --allow-pre-commit-input --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-field-trial-config --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-search-engine-choice-screen --disable-sync --enable-automation --export-tagged-pdf --generate-pdf-document-outline --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold --enable-features=NetworkServiceInProcess2 --headless=new --hide-scrollbars --mute-audio about:blank --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp --remote-debugging-port=0 {
detached: true,
env: { PUPPETEER_LOGLEVEL: 'warn' },
stdio: [ 'pipe', 'pipe', 'pipe' ]
}
puppeteer:browsers:launcher Launched 77
[77:99:0212/184919.101915:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
... 2 minutes pass ...
[77:103:0212/185058.541101:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:103:0212/185058.545833:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:99:0212/185058.659905:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[77:99:0212/185058.664100:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[77:99:0212/185058.664193:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[77:99:0212/185058.664208:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[77:99:0212/185100.545069:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[77:99:0212/185100.545120:ERROR:bus.cc(407)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
DevTools listening on ws://127.0.0.1:39321/devtools/browser/c2bc3dd3-e056-4850-80d3-03782d2bbde9
puppeteer:protocol:SEND ► [
'{"method":"Target.setDiscoverTargets","params":{"discover":true,"filter":[{}]},"id":1}'
]
[77:146:0212/185102.787508:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:146:0212/185102.787592:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:146:0212/185102.787668:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:146:0212/185102.787814:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[77:146:0212/185102.787863:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
puppeteer:protocol:RECV ◀ [
'{"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"75B8C5DD3A56E651FB1725FD3E7F6890","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"6533EE3CE11CFE6B1647EE8CCACB8D60"}}}'
]
... then it finally starts to log a lot and work ...
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
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 18 (11 by maintainers)
@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.