GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: refactor tracing code by addaleax · Pull Request #21867 · nodejs/node

Conversation

@addaleax

@addaleax addaleax commented Jul 18, 2018

Copy link
Copy Markdown
Member

This addresses a number with issues with our tracing code related to code style, readability, race conditions, memory leaks, file descriptor leaks, and other bugs.

I hope that this might help a bit with the flaky test situation around trace_events.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss, jasnell, TimothyGu, and BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 4 reactions
@addaleax
addaleax requested review from eugeneo, jasnell and ofrobots July 18, 2018 10:20
@nodejs-github-bot

nodejs-github-bot commented Jul 18, 2018

Copy link
Copy Markdown
Collaborator

@addaleax build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/302/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Jul 18, 2018
@addaleax addaleax added the trace_events Issues and PRs related to trace events from V8, Node.js core, and user code. label Jul 18, 2018
@addaleax

addaleax commented Jul 18, 2018

Copy link
Copy Markdown
Member Author

Btw, this might not completely resolve the issues with this code – but I think this is an improvement over the current situation.

Full CI: https://ci.nodejs.org/job/node-test-pull-request/15929/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes Jul 18, 2018
View reviewed changes
@eugeneo

eugeneo commented Jul 18, 2018

Copy link
Copy Markdown
Contributor

Sorry, I do not have a time to do a proper review today. I had been working on an alternative implementation for this (80% done), just want to share design..

  1. File writer and inspector writers live entirely on a "tracing thread". I.e. no asyncs, no mutexes, etc.
  2. node_trace_buffer is fully thread safe (all calls are synchronized).
  3. tracing/agent.cc is the one that passes buffers from "any" thread (i.e. the thread that trace controller chose to call the buffer) to the writers on the tracing thread.
  4. inspector protocol writer uses MainThreadInterface to pass the message from the tracing thread to the inspector dispatcher on the main thread.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jul 18, 2018

Copy link
Copy Markdown
Member Author

@eugeneo If you’d like to share code, I’m happy to take a look!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eugeneo

eugeneo commented Jul 19, 2018

Copy link
Copy Markdown
Contributor

@addaleax https://github.com/eugeneo/node/tree/single-threaded-tracing - this is my wip branch, but it does not even compile.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eugeneo
eugeneo approved these changes Jul 23, 2018
View reviewed changes
@eugeneo

eugeneo commented Jul 23, 2018

Copy link
Copy Markdown
Contributor

I would like to suggest adding a test case, e.g. - https://github.com/eugeneo/node/blob/19379fef2767dcb691b75b432a76bc0715a3ffe1/test/parallel/test-tracing-no-crash.js

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ofrobots
ofrobots approved these changes Jul 26, 2018
View reviewed changes
@ofrobots

ofrobots commented Jul 26, 2018

Copy link
Copy Markdown
Contributor

New CI: https://ci.nodejs.org/job/node-test-pull-request/16009/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax
addaleax force-pushed the tracing branch from 17fc171 to 0bbe35a Compare July 27, 2018 17:35
@addaleax

addaleax commented Jul 27, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

New CI: https://ci.nodejs.org/job/node-test-pull-request/16033/

(edit: Windows failures are real)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax mentioned this pull request Jul 31, 2018
Segfault when spawning child with trace events enabled #22042
Closed
addaleax added 11 commits August 1, 2018 15:11
@addaleax
src: reduce unnecessary includes
2cd8e37
A forward declaration suffices and means that the tracing
agent header and its dependencies don’t need to be included
in nearly every Node.js file.
@addaleax
src: minor refactor of node_trace_events.cc
0bb51a5
Avoid unnecessary copies/extra operations & align with our style guide,
and add protection against throwing getters.
@addaleax
src: refactor tracing agent code
b688231
Avoid unnecessary operations, add a bit of documentation,
and turn the `ClientHandle` smart pointer alias into a real
class.

This should allow de-coupling the unnecessary combination of
a single specific `file_writer` from `Agent`.
@addaleax
src: refactor default trace writer out of agent
769acbb
The agent code is supposed to manage multiple writers/clients.
Adding the default writer into the mix breaks that encapsulation.
Instead, manage default options through a separate "virtual"
default client handle, and keep the file writer management
all to the actual users.
@addaleax
src: fix tracing if cwd or file path is inaccessible
f030398
Otherwise this would have crashed the process.
In particular, checking the return value of an libuv call against `-1`
was invalid to begin with, as libuv uses it to propagate the
error code.
@addaleax
src: close tracing event loop
58e6413
Clean up resources when tearing down the tracing agent.
@addaleax
src: initialize file trace writer on tracing thread
cf9734c
Run the initialization for the file trace writer’s `uv_async_t`s
on the same thread as `uv_run()` for their loop to avoid race
conditions.
@addaleax
src: plug trace file file descriptor leak
94c0449
Close existing file descriptors before overriding
the field with new ones.

Also, use `nullptr` as the loop for these synchronous
operations, since they do not run on the same thread
as the `uv_run()` call for the previously used loop.
@addaleax
src: use unique_ptr for internal JSON trace writer
fc85207
@addaleax
src: use only one tracing write fs req at a time
2fb4258
Concurrent writes to the same fd are generally not ideal,
since it’s not generally guaranteed that data from those
writes will end up on disk in the right order.
@addaleax
src: clean up agent loop when exiting through destructor
74efd1f
addaleax added a commit that referenced this pull request Aug 1, 2018
@addaleax
src: use unique_ptr for internal JSON trace writer
25fdab5
PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
addaleax added a commit that referenced this pull request Aug 1, 2018
@addaleax
src: use only one tracing write fs req at a time
5e83a2a
Concurrent writes to the same fd are generally not ideal,
since it’s not generally guaranteed that data from those
writes will end up on disk in the right order.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
addaleax added a commit that referenced this pull request Aug 1, 2018
@addaleax
src: clean up agent loop when exiting through destructor
281e5a3
Fixes: #22042

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
addaleax pushed a commit that referenced this pull request Aug 1, 2018
Eugene Ostroukhov @addaleax
test: add tracing crash regression test
55623b5
PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
@addaleax
addaleax deleted the tracing branch August 1, 2018 15:28
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: reduce unnecessary includes
cde0e5f
A forward declaration suffices and means that the tracing
agent header and its dependencies don’t need to be included
in nearly every Node.js file.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: minor refactor of node_trace_events.cc
4379140
Avoid unnecessary copies/extra operations & align with our style guide,
and add protection against throwing getters.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: refactor tracing agent code
daafe6c
Avoid unnecessary operations, add a bit of documentation,
and turn the `ClientHandle` smart pointer alias into a real
class.

This should allow de-coupling the unnecessary combination of
a single specific `file_writer` from `Agent`.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: refactor default trace writer out of agent
c101b39
The agent code is supposed to manage multiple writers/clients.
Adding the default writer into the mix breaks that encapsulation.
Instead, manage default options through a separate "virtual"
default client handle, and keep the file writer management
all to the actual users.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: fix tracing if cwd or file path is inaccessible
4c9c1bb
Otherwise this would have crashed the process.
In particular, checking the return value of an libuv call against `-1`
was invalid to begin with, as libuv uses it to propagate the
error code.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: close tracing event loop
56edd5f
Clean up resources when tearing down the tracing agent.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: initialize file trace writer on tracing thread
89e2302
Run the initialization for the file trace writer’s `uv_async_t`s
on the same thread as `uv_run()` for their loop to avoid race
conditions.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: plug trace file file descriptor leak
ce48936
Close existing file descriptors before overriding
the field with new ones.

Also, use `nullptr` as the loop for these synchronous
operations, since they do not run on the same thread
as the `uv_run()` call for the previously used loop.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: use unique_ptr for internal JSON trace writer
6b58746
PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: use only one tracing write fs req at a time
ba480d3
Concurrent writes to the same fd are generally not ideal,
since it’s not generally guaranteed that data from those
writes will end up on disk in the right order.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
@addaleax @targos
src: clean up agent loop when exiting through destructor
00c33a5
Fixes: #22042

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
targos pushed a commit that referenced this pull request Aug 1, 2018
Eugene Ostroukhov @targos
test: add tracing crash regression test
c2372ea
PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
@rvagg rvagg mentioned this pull request Aug 13, 2018
Release proposal: v10.9.0 #22295
Merged
This was referenced Aug 16, 2018
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#230
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#215
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#231
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#216
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#232
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#217
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#233
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#218
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#234
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#219
Closed
@renovate renovate Bot mentioned this pull request Feb 8, 2019
Update Node.js to v10.9.0 mozilla/treeherder#3929
Merged
@renovate renovate Bot mentioned this pull request Feb 19, 2019
chore(deps): update node.js to v10.9.0 jaypeng2015/aws-this-week#58
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell approved these changes
+2 more reviewers
@ofrobots ofrobots ofrobots approved these changes
@eugeneo eugeneo eugeneo approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. trace_events Issues and PRs related to trace events from V8, Node.js core, and user code.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@addaleax @nodejs-github-bot @eugeneo @ofrobots @jasnell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.