Skip to content
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

Crashes on Apple Silicon #152

Closed
jackHedaya opened this issue Jan 11, 2021 · 36 comments · Fixed by #201
Closed

Crashes on Apple Silicon #152

jackHedaya opened this issue Jan 11, 2021 · 36 comments · Fixed by #201

Comments

@jackHedaya
Copy link

Describe the bug
On Apple Silicon, Chromium will crash on launch with the following message:

app_1 | Error: Protocol error (Target.setDiscoverTargets): Target closed.

app_1 | at /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:71:63

app_1 | at new Promise (<anonymous>)

app_1 | at Connection.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:70:16)

app_1 | at Function.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:95:26)

app_1 | at ChromeLauncher.launch (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js:101:56)

app_1 | at processTicksAndRejections (internal/process/task_queues.js:93:5)

To Reproduce

  1. Execute $ docker-compose up --build -d
  2. See error

What is the expected behavior?
Chrome not to crash

What is the actual behavior?
Chrome crashes

Possible solution
Not sure –– hoping someone here might know what's going on

Logs
If applicable, add logs to help explain your problem.

Versions

  • Chromium: Chromium 86.0.4240.111
  • Image: zenika/alpine-chrome@sha256:2847c4e24af279ee12eea011ba9f669dd92adf317d01fcf3a7a51f88f8a8214b
    Docker Engine: 20.10.1
  • Puppeteer: 5.5.0

Additional context
This happens very rarely when running the program locally. When running through the image, this happens every time.

@jackHedaya jackHedaya added the bug label Jan 11, 2021
@jlandure
Copy link
Member

Hi @jackHedaya 👋

Thanks for the feedback. 👍

Can you share information about your docker-compose setup?
What's the Docker command line or options used?
Are you using the puppeteer example available here ?

Thanks!

@jackHedaya
Copy link
Author

jackHedaya commented Jan 13, 2021

Thank you for reaching out and sure!

Dockerfile

FROM zenika/alpine-chrome:with-node

# Prevent yarn from reinstalling Chrome
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser

# Set Node to production
ENV NODE_ENV production

# Set app working directory
WORKDIR /usr/src/app

# Copy dependency list and install
COPY --chown=chrome package.json yarn.lock ./
RUN yarn install --unsafe-perm=true --production --frozen-lockfile 

# Install pm2 globally as root then switch back
USER root
RUN npm install -g pm2
USER chrome

# Copy files to working directory
COPY --chown=chrome ./dist .

# Set up process manager and run Express
ENTRYPOINT [ "tini", "--" ]
CMD [ "pm2-runtime", "npm", "--", "start" ]

docker-compose.yml

version: '3'
services:
  app:
    build: .
    env_file:
      - .env
    ports:
      - '3001:3001'

Puppeteer Initializer

protected async createBrowser(
    args?: import('puppeteer').LaunchOptions
  ): Promise<import('puppeteer').Browser> {
    return puppeteer.launch({
      headless: true,
      args: ['--no-sandbox', '--disable-setuid-sandbox'],
      ...args,
    })
  }

@jlandure
Copy link
Member

Hi @jackHedaya

Thanks for the example! 👍
Did you succeed on a classic machine? not an Apple Silicon?

@jackHedaya
Copy link
Author

I've never encountered this problem before while using an Intel Mac

@Joebayld
Copy link

I have the same issue on apple silicon. Any news on this?

@jlandure
Copy link
Member

Hi @jackHedaya @Joebayld 👋

Sorry but I didn't have a Apple Silicon. 😊

Have you seen this issue from the Puppeteer side?
puppeteer issue: puppeteer/puppeteer#6622

Please notice that I don't know how Docker is working on Apple Silicon. It's a ARM based computer.

Perhaps you could make some tests to discover where is the problem...

  1. Does your code work well outside of this Docker image?
  2. Do you succeed to launch a simple Docker container like docker container run docker/whalesay cowsay Hello ?

@Joebayld
Copy link

I only have Apple Silicon so that's all I can test at the moment! Lol

The issue doesn't exist when running outside the docker image (npm start), and it doesn't exist when deploying to a Google Cloud Run server. So it seems to only be Docker on macOS AS.

I can run that example container just fine. And I can also run the alpine-chrome container as well - I just get an error when making calls to puppeteer in the container.

I'll poke the puppeteer folks as it might be an issue with the library - I'm not sure!

@jlandure
Copy link
Member

jlandure commented Feb 1, 2021

Hi @Joebayld 👋

Thanks for the update! 🙌
Please keep me updated!

@jlandure
Copy link
Member

Hi @Joebayld @jackHedaya 👋

Does it work now on Apple Silicon? 😊

@jlandure
Copy link
Member

Any news @Joebayld @jackHedaya ? 😊
Thanks!

@jackHedaya
Copy link
Author

Hi! As of now it is not working, I believe it may be a puppeteer problem though. It seems to be attached to this issue

@jlandure
Copy link
Member

Hi @jackHedaya

Thanks for the update! 👍

@vityas-off
Copy link

puppeteer/puppeteer#1947 (comment) helped me solve this issue

@drpayyne
Copy link

Hi @jlandure, are there any plans to publish a multi-arch image on Docker Hub for with-puppeteer?

@ssoper
Copy link

ssoper commented Sep 5, 2021

I was running into crashes using my new MacBook M1 Air whereas my previous Intel MacBook had no issues. Ended up building my own version of this with an arm64v8 alpine image and my crash issue was resolved. You can find the image at avidtraveler/alpine-chrome.

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

That's great, @ssoper! Could you please publish your customized Dockerfile and its context files if possible?

@jlandure
Copy link
Member

jlandure commented Sep 7, 2021

Hi @ssoper 👋

Thanks for the update!
And congrats to make it working with M1.

Do you think you can contribute to this image by adding your arm64v8 version? 👍
It could be interesting for @drpayyne and the rest of the community 😊

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Hi @jlandure, what's the image build process that you use? I'd love to contribute to making this repo multi-arch as well :)

@jlandure
Copy link
Member

jlandure commented Sep 7, 2021

Hi @drpayyne

Thanks for your motivation 💪

Very simple: the build process is done using Docker Hub AutoBuild.

💬 If you're interested, please create a PR and we will discuss about making the repo multi-arch!

@ssoper
Copy link

ssoper commented Sep 7, 2021

@drpayyne @jlandure the only difference is the very first line FROM arm64v8/alpine:latest, everything else in the Dockerfile is identical.

Here is my fork, lmk what next steps are, happy to help out.

I am running the ARM native version of Docker Desktop v20.10.8 on Big Sur.

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Is there a reason we need to use that specific image? alpine:latest already provides multi-arch images at https://hub.docker.com/_/alpine?tab=tags&page=1&ordering=last_updated&name=latest.

I've been working on rebuilding existing images for both architectures so all that we need to do is rebuild our images for both platforms. We have to maybe customize the images a little, but I'll need to look into the specifics for this repository. Let me get back on this with a PR.

@ssoper
Copy link

ssoper commented Sep 7, 2021

@drpayyne when I specified the platform in the docker command to retrieve and run the image, it claimed there was no such platform.

docker: Error response from daemon: image with reference zenika/alpine-chrome was found but does not match the specified platform: wanted linux/arm64/v8, actual: linux/amd64.

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Yes, you're right. This repository's images (zenika/*) do not provide ARM builds. But the source image you had mentioned that you modified isn't required is what I mean.

the only difference is the very first line FROM arm64v8/alpine:latest, everything else in the Dockerfile is identical.

So we can continue using alpine:latest as the source image and we have to build the same Dockerfile for multiple platforms. I use this command to build the Dockerfile for multiple platforms - docker buildx build --platforms=linux/arm64,linux/amd64 ..

So effectively we just need to rebuild the same Dockerfile for ARM.

Note: Some Dockerfiles here like puppeteer need some customization which I'll be looking into once I fix my PHP rebuild :)

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

@ssoper - I've just rebuilt the base image of this repository for both architecture at https://github.com/drpayyne/chrome/pkgs/container/chrome. All users can pull this tag and it'll download the appropriate architecture.

@ssoper
Copy link

ssoper commented Sep 7, 2021

@drpayyne did it resolve your crash issue?

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

I'm not sure as to what exactly is causing the crash reported here, but you could test it out by running docker run -it --rm ghcr.io/drpayyne/chrome bash. Any feedback is appreciated! I'm currently building the rest of the images like Node and Puppeteer, so I'll test them all together.

@ssoper
Copy link

ssoper commented Sep 7, 2021

the crashes I was seeing locally were related to being unable to parse /proc/self/maps along with a host of GPU errors.

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Any specific commands that I need to test? @ssoper

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

I'm publishing the multi-arch packages at https://github.com/drpayyne?tab=packages&repo_name=chrome. Please test anything you can

@ssoper
Copy link

ssoper commented Sep 7, 2021

@drpayyne ran your image against my complex series of browser interactions (primarily with the E*TRADE website) and it worked perfect 💯

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

That's awesome! Let me check if all the Dockerfiles in this repo build, and then I'll create a PR

cc/ @jlandure

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

@ssoper, I'm getting the below error if I run the base chrome image. Any idea what's causing this in my machine since it seems to work for you? I'm seeing a few answers online, but not sure which is the best approach to fix this.

docker run -it --rm ghcr.io/drpayyne/chrome bash

Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
[0907/154002.918286:FATAL:zygote_host_impl_linux.cc(191)] Check failed: ReceiveFixedMessage(fds[0], kZygoteBootMessage, sizeof(kZygoteBootMessage), &boot_pid).
Received signal 6
[end of stack trace]

@ssoper
Copy link

ssoper commented Sep 7, 2021

might come down to what arguments you are launching with, here is my run command. could also depend on what version of Docker you’re running (I noted in a prev comment what I’m running)

docker container run -d -p 9222:9222 ghcr.io/drpayyne/chrome --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" about:blank

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Ah! Thank you. Just found #33 too. My bad, apologies. My multi-arch image builds work good in that case.

@ssoper
Copy link

ssoper commented Sep 7, 2021

great to hear @drpayyne! @jlandure what work remains so that we can pull zenika/alpine-chrome with a --platform linux/arm64/v8 switch to get the image we need?

@drpayyne
Copy link

drpayyne commented Sep 7, 2021

Discussion PR opened at #182.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants