0

背景:我有这个代码在 AWS linux AMI 中工作,节点 8 用于 lambda。由于亚马逊在 lambda 中停止了节点 8,我一直在努力过渡到现在使用亚马逊 linux 2 的节点 10。自从升级以来,我一直无法克服错误:套接字挂起问题。

版本集

  • 节点 v10.18.1
  • 铬-aws-lambda 2.0.2
  • 傀儡师 2.0.0
  • Amazon Linux 第 2 版 (Karoo)

代码片段:

console.log('start 1')
try {
        // create the browser session and page. Then go to url 
        const browser = await puppeteer.launch({
            // devtools: true
            args: chrome.args,
            defaultViewport: chrome.defaultViewport,
            executablePath: await chrome.executablePath,
            headless: chrome.headless,   
        })

        console.log('start 2')

        const page = await browser.newPage()

        console.log('starting browser logic')

        // set page timeout out milisecods, currently 2
        page.setDefaultTimeout(pageTimeOut)

        // goes to webpage waits for network traffic to die off
        const [startPage] = await Promise.all([
            page.goto(url),
            page.waitForNavigation({waitUntil: "networkidle0"})
        ])

错误:错误发生在 await puppeteer.launch

bash-4.2# node run.js
starting check: LoginCheck
start 1
ErrorEvent {
  target:
   WebSocket {
     domain: null,
     _events:
      [Object: null prototype] { open: [Function], error: [Function] },
     _eventsCount: 2,
     _maxListeners: undefined,
     readyState: 3,
     protocol: '',
     _binaryType: 'nodebuffer',
     _closeFrameReceived: false,
     _closeFrameSent: false,
     _closeMessage: '',
     _closeTimer: null,
     _closeCode: 1006,
     _extensions: {},
     _receiver: null,
     _sender: null,
     _socket: null,
     _isServer: false,
     _redirects: 0,
     url:
      'ws://127.0.0.1:41553/devtools/browser/cd72d3b1-e70e-4a34-aa65-351ef1857587',
     _req: null },
  type: 'error',
  message: 'socket hang up',
  error:
   { Error: socket hang up
       at createHangUpError (_http_client.js:323:15)
       at Socket.socketOnEnd (_http_client.js:426:23)
       at Socket.emit (events.js:203:15)
       at Socket.EventEmitter.emit (domain.js:448:20)
       at endReadableNT (_stream_readable.js:1145:12)
       at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET' } }
4

1 回答 1

1

我能够通过安装以下 AWS linux 2 库来解决此问题。

pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 alsa-lib.x86_64 gtk3.x86_64 xorg-x11-fonts-100dpi xorg-x11-utils xorg-x11-fonts-Type1 xorg-x11-fonts-misc xorg-x11-fonts-cyrillic xorg-x11-fonts-75dpi ipa-gothic-fonts atk.x86_64 GConf2.x86_64 avahi.x86_64 
于 2020-01-30T21:13:12.367 回答