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

Grover::JavaScript::ProtocolError: Network.enable timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. #248

Open
JosephTico opened this issue Aug 1, 2024 · 6 comments

Comments

@JosephTico
Copy link

This is a very weird thing, never had any issue related to timeouts until a couple days ago and this has started happening randomly, not every request to Grover does this. Using Alpine 3.20.

My initializer:

# config/initializers/grover.rb
Grover.configure do |config|
  config.options = {
    format: 'letter',
    emulate_media: 'screen',
    margin: {
      top: '1cm',
      bottom: '1cm',
    },
    print_background: true,
    cache: false,
    scale: 0.75
  }
end

I'm using Rails 7.1, Ruby 3.3.3. For Rendering PDFs I use this helper function that renders the action to a string and passes it to Grover.

  def render_pdf(template, disposition: 'inline', filename: 'file')
      send_data(
        Grover.new(
          render_to_string(
            {
              action: action_name.to_s,
              formats: [:pdf],
              template:,
              layout: 'pdf'
            }
          )
        ).to_pdf, disposition:, filename: "#{filename}.pdf", type: 'application/pdf'
      )
  end

Any ideas? Thank you.

@CeeBeeUK
Copy link

CeeBeeUK commented Aug 2, 2024

About to ask the same question... except 100% of our pdf generations are failing

We have spent a few days trying different debugging issues, the only obvious thing to change was chromium incrementing from 126 to 127

On a broken environment, opening node and running

(async () => {
  const puppeteer = require("puppeteer");
  // Launch the browser and open a new blank page
  const browser = await puppeteer.launch({args:['--disable-gpu', '--no-sandbox','--disable-setuid-sandbox']});
  const page = await browser.newPage();
  const version = await page.browser().version();
  console.log("page browser version: " + version);
  await page.goto('https://bbc.co.uk/news');

  console.log("Page title: " + await page.title());

  const element = await page.waitForSelector('h1')
  let value = await element.evaluate(el => el.textContent)
  console.log('h1 = ' + value);

  await browser.close();
})();

returns

page browser version: Chrome/127.0.6533.88
Page title: Home - BBC News
h1 = BBC News

But when I start a rails console and run

Grover.new('test').to_pdf

it will hang and return the error above, but running the same sequence on a working build returns PDF output

The working infrastructure is:
Alpine 3:20
Grover 1.1.9
Puppeteer 22.13.1
Chromium 126.0.6478.182 Alpine Linux

Broken infrastructure:
Alpine 3:20
Grover 1.1.9
Puppeteer 22.13.1
Chromium 127.0.6533.72 Alpine Linux

We have updated a build this morning to use the latest Chromium 127.0.6533.88 Alpine Linux but it is still failing

@JosephTico
Copy link
Author

Yeah, it looks like this is a Puppeteer issue with Alpine 3.20's Chromium version.

For now a quick fix is downgrading to Alpine 3.19 as it looks like it's using a different Chromium that is still compatible.

@CeeBeeUK
Copy link

CeeBeeUK commented Aug 2, 2024

I'm not sure it is puppeteer... if you launch puppeteer via node it successfully renders pages

But yes, rolling back to Alpine 3:19 and puppeteer 22.7.1 seems to be our only recourse to get this working

@JosephTico
Copy link
Author

I think it could be related to this:

puppeteer/puppeteer#11640 (comment)

The thing making it fail appears to be the --single-process flag which I assume Grover could be setting.

More issues related to this on Puppeteer's repo:

puppeteer/puppeteer#12637
puppeteer/puppeteer#12189

@CeeBeeUK
Copy link

CeeBeeUK commented Aug 2, 2024

I'm having some success with changing my Grover configuration launch_args
from

launch_args: %w[--no-sandbox]

to

launch_args: %w[--disable-gpu --no-sandbox]

My testing is continuing but, so far, it is looking hopeful

@abrom
Copy link
Contributor

abrom commented Aug 3, 2024

Not sure I can add much to this issue, but I'd welcome an update to the README if/when there is a resolution.

As far as I can tell from the discussion above this isn't a Grover issue, but rather a Chrome/Chromium + your environment issue. Grover does not add/inject any launch arguments that you haven't told it to.

Of course, forewarning others about potential configuration mismatches like this would be great.

tomas-stefano added a commit to DFE-Digital/apply-for-teacher-training that referenced this issue Aug 5, 2024
The response from Grover for downloading PDFs is 3.3 minutes and is
raising timeouts.

This is making the cpu usage skyrocket and restart the prod containers
AND making Apply to be very slow.

Solution
Tried this: Studiosity/grover#248 (comment)
dcyoung-dev pushed a commit to DFE-Digital/apply-for-teacher-training that referenced this issue Aug 5, 2024
## Context

We are experiencing timeout issues when users download PDFs in the
provider interface (download applications and references)

The response for downloading PDFs is reaching 3.3 minutes then a Grover
timeout happens with the spike in CPU usage.

**Then the cpu usage skyrocket and prod containers are restarted several
times AND making Apply to be very slow.**

## Issues in other repos:

Studiosity/grover#248
Studiosity/grover#233


## Solution

Tried this:
Studiosity/grover#248 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants