apify / browser-pool

A Node.js library to easily manage and rotate a pool of web browsers, using any of the popular browser automation libraries like Puppeteer, Playwright, or SecretAgent.
87 stars 14 forks source link

PuppeteerPlugin threw an error - address already in use #48

Closed rubydev closed 2 years ago

rubydev commented 3 years ago

When we kicked off multiple runs on Apify platform, two actors threw same exception in similar time (and main function of actor failed). Both runs contained same IP address and port in log file. Session ID was different.

node: 14 apify SDK: 1.3.4 browser-pool: 1.2.0-beta.1 puppeteer: 10.2.0

2021-09-09T11:45:52.929Z Error: BrowserPool: Could not anonymize proxyUrl: http://groups-RESIDENTIAL,session-session_XXX,country-US:*********@X.X.X.X:XXXX/. Reason: listen EADDRINUSE: address already in use ::.
2021-09-09T11:45:52.931Z at PuppeteerPlugin._getAnonymizedProxyUrl (/home/myuser/app/node_modules/browser-pool/dist/abstract-classes/browser-plugin.js:137:19)
2021-09-09T11:45:52.933Z at runMicrotasks ()
2021-09-09T11:45:52.935Z at processTicksAndRejections (internal/process/task_queues.js:95:5)
2021-09-09T11:45:52.936Z at async PuppeteerPlugin._addProxyToLaunchOptions (/home/myuser/app/node_modules/browser-pool/dist/puppeteer/puppeteer-plugin.js:45:29)
2021-09-09T11:45:52.939Z at async PuppeteerPlugin.launch (/home/myuser/app/node_modules/browser-pool/dist/abstract-classes/browser-plugin.js:93:13)
2021-09-09T11:45:52.941Z at async BrowserPool._launchBrowser (/home/myuser/app/node_modules/browser-pool/dist/browser-pool.js:417:29)
2021-09-09T11:45:52.942Z at async BrowserPool.newPage (/home/myuser/app/node_modules/browser-pool/dist/browser-pool.js:185:33)
2021-09-09T11:45:52.944Z at async PuppeteerCrawler._handleRequestFunction (/home/myuser/app/node_modules/apify/build/crawlers/browser_crawler.js:306:22)
B4nan commented 3 years ago

Can you please test this with latest versions? browser-pool 2.0.2 has a fix for race condition in the newPage method, so it might be very well already fixed.

cc @szmarczak

szmarczak commented 3 years ago

@B4nan This is very different. The race condition I fixed was causing too many tabs open than max allowed.

szmarczak commented 3 years ago

It looks like it failed to generate the port or couldn't find one open. Are you able to reproduce the issue?

rubydev commented 3 years ago

Hi, I’m not able reproduce the issue again - it happened only once. I will let you know, if it will happen again.

szmarczak commented 2 years ago

This is definitely port exhaustion. I'm getting the same error via:

const http = require('http');

const listen = () => {
    http.createServer().listen(0, listen);
};

listen();
Error: listen EADDRINUSE: address already in use ::
    at Server.setupListenHandle [as _listen2] (node:net:1319:16)
    at listenInCluster (node:net:1367:12)
    at Server.listen (node:net:1454:7)
    at Server.listen (/home/szm/Desktop/proxy-chain/ex.js:4:25)
    at Object.onceWrapper (node:events:513:28)
    at Server.emit (node:events:394:28)
    at emitListeningNT (node:net:1353:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1346:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::'
}
rubydev commented 2 years ago

@szmarczak Week ago it happened again. And before it happened, in log was a lot errors like this:

screenshot 386

Can't it be related with this? https://github.com/apify/browser-pool/issues/32

szmarczak commented 2 years ago

This should be fixed now.