browserstack / browserstack-local-nodejs

NodeJS bindings for BrowserStack Local
https://www.browserstack.com
MIT License
71 stars 56 forks source link

browserstack-local sometimes breaks due to Incorrect JSON in stdout #127

Open elukoyanov opened 2 years ago

elukoyanov commented 2 years ago

Expected Behavior

browserstack-local starts and works fine

Actual Behavior

browserstack-local starts and fails with next error

SyntaxError: Unexpected token { in JSON at position 66
    at JSON.parse (<anonymous>)
    at /<project path>/node_modules/browserstack-local/lib/Local.js:59:23
    at ChildProcess.exithandler (node:child_process:388:7)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.emit (node:domain:475:12)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
error Command failed with exit code 1.

Steps to Reproduce the Problem

it's flaky, but often reproduces

  1. start connection to BrowserStack before tests

browserstack local arguments

    local: true,
    localIdentifier: "" // generated id:  `${<project name>}_${os.userInfo().username}_${Math.round(Math.random() * 1e6)}` as string,

    networkLogs: true,
    consoleLogs: "errors",
    resolution: "1280x1024",
    seleniumVersion: "4.0.0-alpha-6", // also reproduced with "4.1.2", "3.141.59"
    idleTimeout: 300,

    os: "Windows",
    osVersion: "10",

    projectName: "" // project name as string,
    sessionName: "" // name as string,
    buildName: "" // name as string,

Platform details

  1. browserstack-local-nodejs version: 1.4.8, also reproduced on 1.4.9
  2. node version: 16.13.0, also reproduced on 14.3.0, 14.18.0
  3. os type and version: ubuntu/macos

Details

I made fork with logging of reponse https://github.com/elukoyanov/browserstack-local/blob/master/lib/Local.js#L61 and I see next stdout:

{"state":"connected","pid":323,"message":{"message":"Connected"}}
{"state":"connected","pid":323,"message":{"message":"Connected"}}
Thu Mar 10 2022 15:59:47 GMT+0000 (Coordinated Universal Time) -- Received runtime exception: Error [ERR_IPC_DISCONNECTED]: IPC channel is already disconnected
Thu Mar 10 2022 15:59:47 GMT+0000 (Coordinated Universal Time) -- Exiting.

As I see - there are duplicated JSON and two strings with error.

It breaks JSON.parse.

As I see, it's more server error, than package. But maybe not