Serverless-chrome: serverless-plugin: ECONNREFUSED

Created on 4 Sep 2017  Â·  10Comments  Â·  Source: adieuadieu/serverless-chrome

@adieuadieu Thanks for starting such an awesome project. I'm trying to follow the README for the project's serverless plugin, but found that the steps documented did not work for me.

Here's what I've tried.

package.json

{
  "name": "serverless-chrome-plugin",
  "version": "0.0.1",
  "description": "hello, does it work?",
  "main": "index.js",
  "scripts": {
    "deploy": "serverless deploy -v"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "chrome-remote-interface": "0.24.5"
  },
  "devDependencies": {
    "serverless": "1.21.0",
    "serverless-plugin-chrome": "1.0.0-11"
  }
}

serverless.yml

service: hello-serverless-chrome-plugin

frameworkVersion: "1.21.0"
provider:
  name: aws
  runtime: nodejs6.10
  region: us-west-2
  stage: dev
  profile: lithiumdev 

plugins:
  - serverless-plugin-chrome

functions:
  hello:
    handler: handler.hello
    description: try out this ol' lambda thing
    memorySize: 1536
    timeout: 60

    events:
      - http:
          path: hello
          method: get

handler.js

const CDP = require('chrome-remote-interface')

module.exports.hello = (event, context, callback, chrome) => {
  // Chrome is already running!

  CDP.Version()
    .then((versionInfo) => {
      callback(null, {
        statusCode: 200,
        body: JSON.stringify({
          versionInfo,
          chrome,
        }),
      })
    })
    .catch((error) => {
      callback(null, {
        statusCode: 500,
        body: JSON.stringify({
          error,
        }),
      })
    })
}

When I invoke on lambda, I get this response:
{"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9222}}

I'm a bit new to both node and CDP. I was wondering, could you suggest what might be going wrong?

Most helpful comment

Hi,

I have a similar issue, I am getting:
"errorMessage": "connect ECONNREFUSED 127.0.0.1:9222",
"errorType": "Error",
"stackTrace": [
"Object.exports._errnoException (util.js:1018:11)",
"exports._exceptionWithHostPort (util.js:1041:20)",
"TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)"
]

when I try to run chrome on lambda serverless.
I deploy from mac.

Thanks!

All 10 comments

Hi Dave,

Could you share your full AWS CloudWatch log for the request? Are you deploying from Windows? (Currently doesn't work.)

On 2017/09/04, at 22:01, Dave Wingate notifications@github.com wrote:

@adieuadieu Thanks for starting such an awesome project. I'm trying to follow the README for the project's serverless plugin, but found that the steps documented did not work for me.

Here's what I've tried.

package.json

{
"name": "serverless-chrome-plugin",
"version": "0.0.1",
"description": "hello, does it work?",
"main": "index.js",
"scripts": {
"deploy": "serverless deploy -v"
},
"author": "",
"license": "ISC",
"dependencies": {
"chrome-remote-interface": "0.24.5"
},
"devDependencies": {
"serverless": "1.21.0",
"serverless-plugin-chrome": "1.0.0-11"
}
}
serverless.yml

service: hello-serverless-chrome-plugin

frameworkVersion: "1.21.0"
provider:
name: aws
runtime: nodejs6.10
region: us-west-2
stage: dev
profile: lithiumdev

plugins:

  • serverless-plugin-chrome

functions:
hello:
handler: handler.hello
description: try out this ol' lambda thing
memorySize: 1536
timeout: 60

events:
  - http:
      path: hello
      method: get

handler.js

const CDP = require('chrome-remote-interface')

module.exports.hello = (event, context, callback, chrome) => {
// Chrome is already running!

CDP.Version()
.then((versionInfo) => {
callback(null, {
statusCode: 200,
body: JSON.stringify({
versionInfo,
chrome,
}),
})
})
.catch((error) => {
callback(null, {
statusCode: 500,
body: JSON.stringify({
error,
}),
})
})
}
When I invoke on lambda, I get this response:
{"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9222}}

I'm a bit new to both node and CDP. I was wondering, could you suggest what might be going wrong?

―
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Are you deploying from Windows?

Nope, deploying from OSX.

Could you share your full AWS CloudWatch log for the request?

Sure. I _think_ this is what you're asking for. Lemme know if not.

START RequestId: b31d77db-91aa-11e7-8f1e-fd56d6ca957a Version: $LATEST
END RequestId: b31d77db-91aa-11e7-8f1e-fd56d6ca957a
REPORT RequestId: b31d77db-91aa-11e7-8f1e-fd56d6ca957a  Duration: 16.83 ms  Billed Duration: 100 ms Memory Size: 1536 MB    Max Memory Used: 22 MB  

I found more complete cloudwatch logs after enabling ```DEBUG: "*" in my serverless.yml

START RequestId: be801d16-91b3-11e7-b723-21f409e5b175 Version: $LATEST
2017-09-04T20:58:06.940Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Spawning headless shell
2017-09-04T20:58:06.946Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda ChromeLauncher No debugging port found on port 9222, launching a new Chrome.
2017-09-04T20:58:06.973Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Launcher Chrome running with pid 12 on port 9222.
2017-09-04T20:58:06.974Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 0
2017-09-04T20:58:07.478Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 1
2017-09-04T20:58:07.979Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 2
2017-09-04T20:58:08.479Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 3
2017-09-04T20:58:08.980Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 4
2017-09-04T20:58:09.482Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 5
2017-09-04T20:58:09.983Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 6
2017-09-04T20:58:10.484Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 7
2017-09-04T20:58:10.985Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 8
2017-09-04T20:58:11.487Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 9
2017-09-04T20:58:11.988Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Waiting for Chrome 10
2017-09-04T20:58:11.989Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda Error trying to spawn chrome: { Error: connect ECONNREFUSED 127.0.0.1:9222
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 9222 }
2017-09-04T20:58:11.995Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda stdout log: 
2017-09-04T20:58:11.995Z    be801d16-91b3-11e7-b723-21f409e5b175    @serverless-chrome/lambda stderr log: /var/task/node_modules/@serverless-chrome/lambda/dist/headless_shell: /var/task/node_modules/@serverless-chrome/lambda/dist/headless_shell: cannot execute binary file

2017-09-04T20:58:11.995Z    be801d16-91b3-11e7-b723-21f409e5b175    Error occured in serverless-plugin-chrome wrapper when trying to ensure Chrome for hello() handler.
{}
Error: Unable to start Chrome. If you have the DEBUG env variable set,there will be more in the logs.
at /var/task/node_modules/@serverless-chrome/lambda/dist/bundle.cjs.js:304:13
at throw (native)
at step (/var/task/node_modules/@serverless-chrome/lambda/dist/bundle.cjs.js:257:191)
at /var/task/node_modules/@serverless-chrome/lambda/dist/bundle.cjs.js:257:402
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
END RequestId: be801d16-91b3-11e7-b723-21f409e5b175
REPORT RequestId: be801d16-91b3-11e7-b723-21f409e5b175  Duration: 5058.64 ms    Billed Duration: 5100 ms Memory Size: 1536 MB   Max Memory Used: 24 MB  

After thinking about it for a while, I think I found the root of the issue. The AMI for the Lambdas was updated to the 2017.03 version.

I ran a simple lambda doing cat /etc/system-release and this was the output:

"Amazon Linux AMI release 2017.03\n"

Tomorrow I will try to recompile Chrome 61 with the Lambda patch using the "Amazon Linux AMI release 2017.03" image.

@adieuadieu I tried to recompile Chrome 61 with your change use_dev_shm = false;, using the Amazon Linux AMI release 2017.03. However, I am still getting the error /var/task/node_modules/@serverless-chrome/lambda/dist/headless_shell: cannot execute binary file.

Do you know what else to do to debug this? I thought of compiling a debug version of Chrome. Maybe there is some other flag that I could pass to normal Chrome to debug why this is happening?

I found a workaround, for anyone interested. https://github.com/adieuadieu/serverless-chrome/issues/65

There was a bug in Serverless CLI... https://github.com/serverless/serverless/pull/4189

We can close this ticket as soon as you confirm it works.

Solution

Update Serverless to 1.21.1.

npm install -g [email protected]

We can close this ticket as soon as you confirm it works.

@carlosbaraza @adieuadieu confirmed ... Once I upgraded to serverless 1.21.1, issue was resolved for me. Thanks!

Hi,

I have a similar issue, I am getting:
"errorMessage": "connect ECONNREFUSED 127.0.0.1:9222",
"errorType": "Error",
"stackTrace": [
"Object.exports._errnoException (util.js:1018:11)",
"exports._exceptionWithHostPort (util.js:1041:20)",
"TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)"
]

when I try to run chrome on lambda serverless.
I deploy from mac.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adieuadieu picture adieuadieu  Â·  11Comments

teledyn picture teledyn  Â·  7Comments

Huljo picture Huljo  Â·  6Comments

sepulworld picture sepulworld  Â·  10Comments

alessbelli picture alessbelli  Â·  3Comments