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

bug: Seems to hang for ever on my build agent #83

Closed
ed-sparkes opened this issue Feb 17, 2021 · 5 comments
Closed

bug: Seems to hang for ever on my build agent #83

ed-sparkes opened this issue Feb 17, 2021 · 5 comments
Labels

Comments

@ed-sparkes
Copy link

ed-sparkes commented Feb 17, 2021

Context:

Trying to run this on my azure devops build agent ( Ubuntu-20.04)

I install using sudo npm install md-to-pdf -g -unsafe-perm=true

then run simply md-to-pdf Release1.0.0.md

When i do this on my local machine a pdf is generated in less than a second

On my build agent it hangs indefinitely

Strangely if i kill the task i see this in the logs

[17:18:10] generating PDF from Release1.0.0.md [started]
[17:18:12] generating PDF from Release1.0.0.md [completed]

so it seems it is running in about 2 seconds, but not existing properly so the script task doesnt exit

UPDATE - I managed to work around it by using the following syntax cat file.md | md-to-pdf > path/to/output.pdf but leaving this open in case the above issue is of interest to you

Thanks

@ed-sparkes ed-sparkes added the bug label Feb 17, 2021
@panvicka
Copy link

Hi, I am running md-to-pdf on my self-hosted Drone CI/CD server and I have the same problem. Locally is the PDF generated in less than 1s but on the build agent, Ubuntu-20.04, it hangs.

Unfortunately the proposed cat git.md | md-to-pdf --config-file config.js > git.pdf did not solve the problem for me (it never finishes). I have to use the config file because I have to set launch_options: { args: ['--no-sandbox'] }.

Has anyone more ideas? Thanks!

@simonhaenisch
Copy link
Owner

Usually if there's a sandboxing issue, you should get an error message that links to the troubleshooting docs. See https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md.

The suggested launch flags for disabling sandboxing are --no-sandbox and --disable-setuid-sandbox. @panvicka you don't need to use a config file, you can also use the CLI flag instead:

md-to-pdf --launch-options '{ "args": ["--no-sandbox", "--disable-setuid-sandbox"] }'

(it has to be JSON-formatted string)

Anyway, those troubleshooting docs have heaps of info for different CI providers and running Puppeteer in the cloud... maybe you can find some info in there that helps you solve this.

Another idea I just had is that you might accidentally be passing the -w or --watch flag down to the command? That would definitely cause it to "hang" because it would only stop on SIGINT. @ed-sparkes maybe that's the reason why stdio mode works for you... in stdio mode the function returns before starting the watch mode.

FWIW I use Github Actions to run tests for this package and it runs just fine 🤷🏻‍♂️

@panvicka
Copy link

Thanks! I had quite a few errors when trying to run the puppeteer at first, but I was able to solve them using the troubleshooting link. I would like to keep the config file as I need some additional settings as well.

module.exports = {
  stylesheet: [
    ' https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css',
  ],
  css: `.page-break { page-break-after: always; }
   .markdown-body { font-size: 11px; }
   .markdown-body pre > code { white-space: pre-wrap; }`,
  body_class: 'markdown-body',
  marked_options: {
    headerIds: false,
    smartypants: true,
  },
  pdf_options: {
    format: 'A5',
    margin: '10mm',
    printBackground: true,
  },
  stylesheet_encoding: 'utf-8',
  launch_options: { args: ['--no-sandbox'] },
};

I will look more into it and you know if I find anything!

@panvicka
Copy link

panvicka commented Mar 7, 2021

A small update from me. I have got it working, even the function mdToPdf works on my self-hosted Drone CI/CD with Docker Runner, both running in a Docker.

  1. part of the yml file that installs puppeteer that works on my server
pipeline:
   build:
      image: node
      commands:
        - npm install
        - npm install puppeteer --only=dev
        - apt-get update
        - apt-get install -y -qq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget > /dev/null
        - node node_modules/puppeteer/install.js
  1. I am running node.js script using the function mdToPdf like this
 pdf = await mdToPdf({ path: pathToMd }, confObj).catch(console.error);

with launch_options: { args: ["--no-sandbox"] in confObj

  1. If you have tried several times failing, restart CI/DC server and Docker service as well (!). At one point my pipeline started working after a hard restart.

@simonhaenisch
Copy link
Owner

Thanks for the update 🙌 I think there's enough info here for now, so I'll go ahead and close this as there's nothing actionable about it for me. But feel free to add more comments about possible solutions or causes of this issue.

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

No branches or pull requests

3 participants