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

Better handle intermittent JSON parsing error #7182

Closed
wants to merge 2 commits into from

Conversation

@bsclifton
Copy link
Member

bsclifton commented Dec 3, 2019

Fixes #6189
Fixes #7207

  • Workaround was put in place for Windows use-case in #2787
  • This appears to work most of the time on Linux 👍(always works other platforms)
  • There are cases where appending this breaks the parsing (ex: last line looks like {"phase":2,"source":{"id":73,"type":8}]})
  • In those cases, fall back is to what the string was before ending with }]}

Root cause not known. Not sure if Node.js fs.readFileSync is waiting for the file to finish writing?

Submitter Checklist:

Test Plan:

  1. Build on Linux (Release)
  2. Run npm run network-audit -- --output_path=src/out/Release/brave
  3. Try a few times; see if you encounter the log statement
  4. Check CI for this PR; verify Linux run (and other platforms) worked great

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions.

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.
@bsclifton bsclifton self-assigned this Dec 3, 2019
@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch 2 times, most recently from 57ba367 to deb03dc Dec 3, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 3, 2019

Issue ran into again (nice) and here's how the fix handled it:

01:38:29  Error parsing JSON SyntaxError: Unexpected token ] in JSON at position 49499689
01:38:29      at JSON.parse (<anonymous>)
01:38:29      at start (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/lib/start.js:147:25)
01:38:29      at Command.listener (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:315:8)
01:38:29      at Command.emit (events.js:210:5)
01:38:29      at Command.parseArgs (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:654:12)
01:38:29      at Command.parse (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:474:21)
01:38:29      at Object.<anonymous> (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/scripts/commands.js:177:4)
01:38:29      at Module._compile (internal/modules/cjs/loader.js:956:30)
01:38:29      at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
01:38:29      at Module.load (internal/modules/cjs/loader.js:812:32) Trying the original non-transformed text
01:38:29  undefined:16305
01:38:29  {"phase":2,"source":{"id":99,"type":8},"time":"12105830","type":34}
01:38:29                                                                     
01:38:29  
01:38:29  SyntaxError: Unexpected end of JSON input
01:38:29      at JSON.parse (<anonymous>)
01:38:29      at start (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/lib/start.js:152:27)
01:38:29      at Command.listener (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:315:8)
01:38:29      at Command.emit (events.js:210:5)
01:38:29      at Command.parseArgs (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:654:12)
01:38:29      at Command.parse (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:474:21)
01:38:29      at Object.<anonymous> (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/scripts/commands.js:177:4)
01:38:29      at Module._compile (internal/modules/cjs/loader.js:956:30)
01:38:29      at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
01:38:29      at Module.load (internal/modules/cjs/loader.js:812:32)

Gonna download the log file and look at a different fix; looks like this log is being cut off and needs proper formation before it parses as JSON

@bsclifton bsclifton changed the title Better handle intermittent JSON parsing error WIP - Better handle intermittent JSON parsing error Dec 3, 2019
@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from deb03dc to 8948dd9 Dec 3, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 3, 2019

Passed on all except Android; going to re-run Android + Linux. Might run Linux a few times, to see if it hits the failed parse condition 👍

@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from 8948dd9 to 2e0403d Dec 3, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 3, 2019

CI passed great on Android this time; Linux also worked without issue. Gonna try one more Linux run, then I think this is ready for consideration

@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from 2e0403d to e808586 Dec 3, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 3, 2019

Perfect! The last build ran into the issue and this work-around worked great 😄 Here's a snippet from the logs:
https://ci.brave.com/job/brave-browser-build-pr/job/PR-7182/8/execution/node/376/log/

16:29:09  Waiting for 10 seconds before reading "/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/network_log.json"
16:29:09  Error parsing JSON SyntaxError: Unexpected token ] in JSON at position 49522853
16:29:09      at JSON.parse (<anonymous>)
16:29:09      at start (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/lib/start.js:154:25)
16:29:09      at Command.listener (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:315:8)
16:29:09      at Command.emit (events.js:210:5)
16:29:09      at Command.parseArgs (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:654:12)
16:29:09      at Command.parse (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/node_modules/commander/index.js:474:21)
16:29:09      at Object.<anonymous> (/home/ubuntu/jenkins/workspace/brave-browser-build-pr_PR-7182/scripts/commands.js:177:4)
16:29:09      at Module._compile (internal/modules/cjs/loader.js:956:30)
16:29:09      at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
16:29:09      at Module.load (internal/modules/cjs/loader.js:812:32)
16:29:09  Trying a second work-around
16:29:09  network audit passed.
@bsclifton bsclifton requested review from jumde, bridiver, iefremov and mkarolin Dec 3, 2019
@bsclifton bsclifton changed the title WIP - Better handle intermittent JSON parsing error Better handle intermittent JSON parsing error Dec 3, 2019
@bsclifton bsclifton requested review from NejcZdovc and diracdeltas Dec 3, 2019
@bsclifton bsclifton modified the milestones: 1.3.x - Dev, 1.4.x - Nightly Dec 3, 2019
lib/start.js Outdated Show resolved Hide resolved
@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from e4929dc to 88cecee Dec 4, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 4, 2019

@bridiver updated! Ready for re-review

@bsclifton bsclifton removed this from the 1.4.x - Nightly milestone Dec 4, 2019
@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from 88cecee to 264b10f Dec 4, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 4, 2019

Per #7207 (comment), I added a commit removing the hacks and then using SIGTERM instead. CI will run again, let's see how it goes

@bsclifton
Copy link
Member Author

bsclifton commented Dec 4, 2019

Looks like even with latest revision (which does SIGTERM, not SIGKILL) Windows still doesn't have proper endings in the JSON (ex: it ends the last line with , and is missing the ]})

More discussion about that in #2787 (comment)

Last possible fix I can try would be to only apply the }]} replacement hack if the platform is Windows. Seems the build did finish as expected on all platforms without having to be killed

@bsclifton
Copy link
Member Author

bsclifton commented Dec 5, 2019

Looks like this worked! 😄

Links to the output for network-audit on each platform:

@bsclifton
Copy link
Member Author

bsclifton commented Dec 5, 2019

@bridiver @diracdeltas this is ready for re-review 😄

SIGKILL was originally put in place with #4036 because PR builder would hang during the old npm run test-security step (eventually, the build would ABORT from reaching the timeout). Sometime after that, the test-security step was broken into two parts (audit_deps and network-audit). In this PR, I removed SIGKILL in favor of SIGTERM and PR builder DID finish as expected on all platforms.

The Windows only hack from #2787 is preserved, but ONLY on Windows (check done via process.platform). macOS and Linux process the logs as-is and did NOT encounter a JSON parse problem. I went into the Jenkins workspace for the macOS instances, downloaded the network-audit.log, and verified they have the proper }]} ending

Given the above, I believe that this PR also solves #7207

Copy link
Member

diracdeltas left a comment

this is a way cleaner solution; nice!

@bsclifton
Copy link
Member Author

bsclifton commented Dec 9, 2019

Created #7281 to follow up on idea @bridiver mentioned here: #7207 (comment)

…JSON terminator hack on Windows

Fixes #6189
Fixes #7207
@bsclifton bsclifton force-pushed the bsc-fix-network-audit branch from 969cd94 to 34ee64b Dec 9, 2019
@bsclifton bsclifton added this to the 1.4.x - Nightly milestone Dec 9, 2019
@bsclifton
Copy link
Member Author

bsclifton commented Dec 10, 2019

Looking at the PR builder run, noticed the following:

Since a failure was seen even with this PR, I don't think PR this properly solves the issue. The work-around I had before does "fix" the issue, but doesn't ensure integrity of the logs

Going to close this and we'll have to revisit at another time

@bsclifton bsclifton closed this Dec 10, 2019
@bsclifton bsclifton removed this from the 1.4.x - Nightly milestone Dec 10, 2019
@bsclifton bsclifton deleted the bsc-fix-network-audit branch Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.