help icon indicating copy to clipboard operation
help copied to clipboard

node:14.15.5-alpine3.12 breaks chromium headless

Open rcollette opened this issue 3 years ago • 5 comments

Environment

  • Platform: MacOS 10.15.7 also OpenShift
  • Docker Version: Docker version 20.10.2, build 2291f61, also Kaniko debug-v1.3.0
  • Node.js Version: 14.15.5
  • Image Tag: node:14.15.5-alpine3.12

Expected Behavior

Chromium-Browser should function in Angular Protractor Chrome headless mode tests.

Current Behavior

Experiencing a socket error of some sort.

11 02 2021 13:13:33.460:INFO [karma-server]: Karma v6.1.0 server started at http://localhost:9876/
11 02 2021 13:13:33.462:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
11 02 2021 13:13:33.465:INFO [launcher]: Starting browser ChromeHeadless
11 02 2021 13:13:34.109:ERROR [launcher]: Cannot start ChromeHeadless
	[0211/131333.645005:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0211/131333.645374:WARNING:dns_config_service_posix.cc(342)] Failed to read DnsConfig.
[0211/131333.645885:FATAL:udev_loader.cc(38)] Check failed: false. 
Received signal 6
  r8: 00007faabd13c244  r9: 000056380a1e17a0 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007faabd13c988 r13: aaaaaaaaaaaaaaaa r14: 000056380a1e3810 r15: 0000000000000043
  di: 0000000000000002  si: 00007faabd13c110  bp: 00007faabd13c110  bx: 0000000000000000
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007faac7e28a71  sp: 00007faabd13c108
  ip: 00007faac7e28a71 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
11 02 2021 13:13:34.109:ERROR [launcher]: ChromeHeadless stdout: 
11 02 2021 13:13:34.109:ERROR [launcher]: ChromeHeadless stderr: [0211/131333.645005:ERROR:bus.cc(393)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0211/131333.645374:WARNING:dns_config_service_posix.cc(342)] Failed to read DnsConfig.
[0211/131333.645885:FATAL:udev_loader.cc(38)] Check failed: false. 
Received signal 6
  r8: 00007faabd13c244  r9: 000056380a1e17a0 r10: 0000000000000008 r11: 0000000000000246
 r12: 00007faabd13c988 r13: aaaaaaaaaaaaaaaa r14: 000056380a1e3810 r15: 0000000000000043
  di: 0000000000000002  si: 00007faabd13c110  bp: 00007faabd13c110  bx: 0000000000000000
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007faac7e28a71  sp: 00007faabd13c108
  ip: 00007faac7e28a71 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.

Possible Solution

Steps to Reproduce

I will include our Dockerfile which shows the alpine packages we are using. If necessary I will try to create a minimal Angular project I can attach but that's going to take a lot longer for me to do.

#This target builds the API server and runs unit tests.
FROM node:14.15.5-alpine3.12 AS base
LABEL type="build"
ENV CHROME_BIN=chromium-browser
#The environment value is case sensitive
RUN   echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
      && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
      && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
      && echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories \
      && apk add --update --no-cache \
      bash \
      git \
      libstdc++ \
      chromium \
      harfbuzz \
      nss \
      freetype \
      ttf-freefont \
      wqy-zenhei
RUN npm install -g @angular/[email protected]

FROM base as copy-files
LABEL type="build"
WORKDIR build
COPY .npmrc .npmrc
COPY package*.json .
COPY packages/pdt-ng/.npmrc packages/pdt-ng/.npmrc
COPY packages/pdt-ng/package.json packages/pdt-ng/package.json
COPY packages/pdt-ng/package-lock.json packages/pdt-ng/package-lock.json
COPY server/package.json server/package.json
COPY server/package-lock.json server/package-lock.json

#Restore
FROM copy-files as restore
ARG NPM_TOKEN
ENV NPM_TOKEN=$NPM_TOKEN
LABEL type="build"
RUN ["npm","run","install:ci"]

#Copy Application
FROM restore as copy-application
LABEL type="build"
COPY . .

#With restore completed, now copy over the entire application.
FROM copy-application as build-and-test
LABEL type="build"
RUN ["npm", "run", "build"]

FROM node:14.15.5-alpine3.12 as application
ENV NODE_ENV=production
ENV MONGO_CONNECTION_STRING=mongodb://host.docker.internal:27017/digital_data_delivery
LABEL type="host"
WORKDIR /app
COPY --from=build-and-test /build/build .
LABEL product=$PRODUCT_NAME
LABEL service=$SERVICE_NAME
EXPOSE 3000/tcp
EXPOSE 3001/tcp
ENTRYPOINT ["node","server.js","--experimental-modules"]

Additional Information

Downgrading to node:14.15.4-alpine3.12 works. The issue appears to be specific to this node/alpine/chromium package combination. Running Node 14.15.5, on MacOS with Chrome browser (i.e. not in Docker) works.

rcollette avatar Feb 11 '21 15:02 rcollette

Same Problem here:

Dockerfiles

Does not work:

FROM node:14.7.0-alpine

RUN echo "${ALPINE_MIRROR}/edge/main" >> /etc/apk/repositories
RUN apk add --no-cache \
        --repository="http://dl-cdn.alpinelinux.org/alpine/edge/community" \
        bash \
        chromium \
        curl 

Works:

FROM node:14.7.0-alpine

RUN apk add --no-cache \
        bash \
        chromium \
        curl

How to reproduce

Run docker and type

/usr/bin/chromium-browser --no-sandbox --headless www.google.de

Now whats the difference between both Dockerfiles. I guess its the chromium-version: Working version

/usr/bin/chromium-browser --product-version
81.0.4044.113

Not working version

/usr/bin/chromium-browser --product-version
86.0.4240.111

So I guess we can break it down to the chromium version. But did not try to alter the node image yet.

Edit: It is not the chromium version since an older build of this image also has version 86.0.4240.111 So I would suggest its one of the edge-dependencies installed

InsOpDe avatar Feb 17 '21 12:02 InsOpDe

Image node:14.15.5-alpine3.13 fixes this issue (for now).

We started seeing the issue in the node:14.15.4-alpine3.12 version as well.

rcollette avatar Feb 18 '21 13:02 rcollette

This is still happening on node:14.17.6-alpine3.14

I think dbus is not installed and manually installing it and starting the daemon seems to solve it

The solve is:

apk add --no-cache dbus chromium chromium-chromedriver
dbus-daemon --system
chromium-browser --headless --disable-gpu --disable-dev-shm-usage --disable-software-rasterizer --remote-debugging-port=9222 --no-sandbox https://google.com

zanechua avatar Sep 03 '21 14:09 zanechua

I'm on node:16-alpine and this is seems like an issue still.

I set --remote-debugging-port=9222 and it magically works for me (what I don't like 😀) without even installing dbus. (I tried to install dbus but it didn't work with the same error,. looks like something has to create "/run/dbus/system_bus_socket" separately as well.)

It seems like when chromium starts it's trying to connect somewhere

It looks like it uses dbus as well as "/run/dbus/system_bus_socket" file(?) https://chromium.googlesource.com/chromiumos/docs/+/HEAD/dbus_best_practices.md#chromeos-d_bus-best-practices (it's for chromiumOS but should be a similar thing for chromium somewhere)

ChromeOS uses D-Bus for inter-process communication. At a high level, >D-Bus consists of a system bus that is managed by a dbus-daemon process. Clients (typically either system daemons or > >Chrome) connect to the system bus via /run/dbus/system_bus_socket and use it to communicate with each other.

and dbus assumes the existence of "/run/dbus/system_bus_socket" file as well https://dbus.freedesktop.org/doc/dbus-specification.html

System message bus A computer may have a system message bus, accessible to all applications on the system. This message bus may be used to broadcast system events, such as adding new hardware devices, changes in the printer queue, and so forth.

The address of the system message bus is given in the DBUS_SYSTEM_BUS_ADDRESS environment variable. If that variable is not set, applications should try to connect to the well-known address unix:path=/var/run/dbus/system_bus_socket. [[3]]> > > (https://dbus.freedesktop.org/doc/dbus-specification.html#ftn.id-1.13.6.4.3.3)

The question is whether dbus and "/run/dbus/system_bus_socket" is something what has to be on any Linux system by "definition" so chromium can assume the existence of these staff on the machine and wouldn't install it....or the other way around? I'd say the latter, cause dbus is a package wherefore meant to be something optional.

And another question is what is "any Linux system" ? I guess node:16-alpine is something that keeps linux as small as possible to support node 16. So everything else, should be installed manually and might break.

Wherefore it's not an issue of node:x-alpine then., maybe it's an issue of Chromium.

Looks like --remote-debugging-port=9222 changes the default behavior of Chromium and it doesn't use dbus.

related Chromium issue

kokushkin avatar Aug 26 '22 10:08 kokushkin