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

Retrying Connection...undefined #775

Open
AxelRothe opened this issue Dec 14, 2023 · 9 comments
Open

Retrying Connection...undefined #775

AxelRothe opened this issue Dec 14, 2023 · 9 comments

Comments

@AxelRothe
Copy link

Hello,

I set up Google Chrome and all dependencies as instructed in the ReadMe.

On my Mac, I can start and test the server. If I move to my Linux VM, I get this result:

2023-12-14T17:01:15.413Z Starting Prerender
2023-12-14T17:01:15.416Z Starting Chrome
2023-12-14T17:01:15.422Z Prerender server accepting requests on port 3000
2023-12-14T17:01:15.995Z retrying connection to Chrome...
2023-12-14T17:01:17.016Z retrying connection to Chrome...
2023-12-14T17:01:18.023Z retrying connection to Chrome...
2023-12-14T17:01:19.030Z retrying connection to Chrome...
2023-12-14T17:01:20.035Z retrying connection to Chrome...
2023-12-14T17:01:21.040Z retrying connection to Chrome...
2023-12-14T17:01:22.044Z retrying connection to Chrome...
2023-12-14T17:01:23.048Z retrying connection to Chrome...
2023-12-14T17:01:24.054Z retrying connection to Chrome...
2023-12-14T17:01:25.063Z retrying connection to Chrome...
2023-12-14T17:01:26.068Z retrying connection to Chrome...
2023-12-14T17:01:27.074Z retrying connection to Chrome...
2023-12-14T17:01:28.081Z retrying connection to Chrome...
2023-12-14T17:01:29.087Z retrying connection to Chrome...
2023-12-14T17:01:30.091Z retrying connection to Chrome...
2023-12-14T17:01:31.094Z retrying connection to Chrome...
2023-12-14T17:01:32.097Z retrying connection to Chrome...
2023-12-14T17:01:33.100Z retrying connection to Chrome...
2023-12-14T17:01:34.104Z retrying connection to Chrome...
2023-12-14T17:01:35.108Z retrying connection to Chrome...
2023-12-14T17:01:35.424Z undefined
2023-12-14T17:01:35.425Z Failed to start and/or connect to Chrome. Please make sure Chrome is running
2023-12-14T17:01:35.426Z Stopping Chrome

I tried setting the location, tried switching to Chromium. Set a different port etc.

Both google-chrome and chromium work fine if you call them via terminal.

@AnantaPodder
Copy link

AnantaPodder commented Dec 28, 2023

Execute them one by one and install chrome correctly. I've tested it on ubuntu.

sudo apt-get update
sudo apt-get install -y libappindicator1 fonts-liberation
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt install --fix-broken
sudo dpkg -i google-chrome*.deb

@ksgy
Copy link

ksgy commented Jan 3, 2024

@AxelRothe For the same issue you had, I had to switch back to node 16 or 17 from node 18

@ShGKme
Copy link

ShGKme commented Jan 22, 2024

Indeed, it works fine on Node 16 and doesn't on Node 18+ with the same issue.

@turicas
Copy link

turicas commented Feb 25, 2024

I had the same problem, tried to debug and had a hard time. After changing the code to debug better, checking all log messages and trying many solutions, I solved the problem but don't know exactly the root cause. I made many changes on my environment and it worked - you can see more details at #779. I think the problems were a combination of:

  • Old versions installed (yarn add installed old versions of chrome-remote-interface and it was not able to run CDP.New due to change from GET to PUT, I think)
  • The code to restart Chrome had a bug and did not start it again at all (at least on Debian GNU/Linux inside Docker)
  • I changed the way prerender connects to the browser using CDP, now forcing the host to be passed along with the port (in one log I saw it trying to connect to ::1 but I was pretty sure IPv6 was not enabled)

@AxelRothe could you please try running the code from this branch?

@bozho
Copy link

bozho commented Mar 29, 2024

We are seeing the same issue here when running on docker 26 on Ubuntu 20.04.

We have a custom docker image currently built from node:19-alpine base image that installs the latest available chromium and uses prerender 5.8.0.

server.js file looks like this:

const prerender = require('prerender');
const prMemoryCache = require('prerender-memory-cache');

const memCache = Number(process.env.MEMORY_CACHE) || 0;
const server = prerender({
    chromeFlags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars', '--disable-dev-shm-usage'],
    forwardHeaders: true,
    chromeLocation: '/usr/bin/chromium-browser',
    userAgent: process.env.USER_AGENT,
});

server.use(prerender.blacklist());
server.use(prerender.httpHeaders());
server.use(prerender.removeScriptTags());

if (memCache === 1) {
    server.use(prMemoryCache);
}
server.start();

This works fine on docker versions 19-25. After upgrading to docker 26, we get the above output.

Listing running processes shows the chrome process, but prerender fails to connect.

Starting the container manually with sh as the entry point and running node server.js shows the same behaviour.

However, starting chrome manually from sh using the same chromeFlags, sending it to the background and then running node server.js works.

Upgrading the base image to node:20-alpine and prerender to 5.20.2 does not help.

@turicas
Copy link

turicas commented Mar 29, 2024

@bozho good debugging!
I just checked Docker 26 release notes and there's some changes in IPv6: "Always attempt to enable IPv6 on a container's loopback interface, and only include IPv6 in /etc/hosts if successful.", referring to moby/moby#47062
So with the commits from #779 (maybe except for d49ceac) you'll probably be able to run it on docker 26.
Could you please try it?

@bozho
Copy link

bozho commented Mar 29, 2024

@turicas What would be the easiest way to do it? Have our Dockerfile copy and overwrite the two files from #779 after installing npm packages?

@turicas
Copy link

turicas commented Mar 30, 2024

@bozho yes, I think this will do it, but you'll need to modify inside node_modules. Other options include:

  • Installing prerender from "PythonicCafe/prerender#enhancement/connection" (as in this package.json)
  • Using this Dockerfile (which depends on the package.json mentioned above)

@bozho
Copy link

bozho commented Apr 2, 2024

@turicas #779 seems to be working!

We run it on a 3-node docker swarm, a replica on each. When starting, one replica logs an error:

2024-04-02T08:47:39.017Z Starting Prerender
2024-04-02T08:47:39.033Z Starting Chrome
2024-04-02T08:47:39.054Z Prerender server accepting requests on port 3000
2024-04-02T08:47:39.617Z Error while running CDP.Version (will retry) Error: connect ECONNREFUSED 127.0.0.1:9222
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 9222
}
2024-04-02T08:47:40.666Z Got webSocketDebuggerURL: ws://127.0.0.1:9222/devtools/browser/6b936a8e-0ff5-467a-9e24-c0155a263c06
2024-04-02T08:47:40.667Z Started Chrome: HeadlessChrome/123.0.6312.86

(my guess is that it tries to connect to port 9222 too quickly)

The other two replicas are fine:

2024-04-02T08:47:37.497Z Starting Prerender
2024-04-02T08:47:37.497Z Starting Chrome
2024-04-02T08:47:37.500Z Prerender server accepting requests on port 3000
2024-04-02T08:47:38.006Z Got webSocketDebuggerURL: ws://127.0.0.1:9222/devtools/browser/c6295031-0995-4e31-bbc5-f7b2f389e5da
2024-04-02T08:47:38.007Z Started Chrome: HeadlessChrome/123.0.6312.86

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

6 participants