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

debugger,test: fix flaky debug logging on SmartOS #3615

Closed
wants to merge 2 commits into from

Conversation

Trott
Copy link
Member

@Trott Trott commented Oct 31, 2015

SmartOS sometimes munges output from process._rawDebug()
but Windows can't use console.error() in the debug agent.
So inject logic to chose the right thing based on platform.

Fixes: #2476

@Trott
Copy link
Member Author

Trott commented Oct 31, 2015

// SmartOS sometimes munges output from `process._rawDebug()`
// but Windows can't use `console.error()`.
// https://github.com/nodejs/node/issues/2476
if (process.platform == 'win32') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

===

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually feel like I need a bath after typing == instead of ===. Not sure how that happened. Will change for sure.

@Trott
Copy link
Member Author

Trott commented Oct 31, 2015

Addressed @cjihrig suggestions, pushed a fixup commit, killed the prior CI and re-running.

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

UPDATE: CI looks good. One went offline during the build failure and a single failure on Windows with a test that's been flaky for a while. Otherwise, all success.

@mscdex mscdex added debugger test Issues and PRs related to the tests. labels Oct 31, 2015
@Trott Trott changed the title test: fix flaky test-debug-signal-cluster.js debugger,test: fix flaky test-debug-signal-cluster.js Nov 1, 2015
@Trott Trott changed the title debugger,test: fix flaky test-debug-signal-cluster.js debugger,test: fix flaky debug logging on SmartOS Nov 1, 2015
// SmartOS sometimes munges output from `process._rawDebug()`
// but Windows can't use `console.error()`.
// https://github.com/nodejs/node/issues/2476
const log = process.platform === 'win32' ? process._rawDebug : console.error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use common.isWindows

Edit: Nvm. This is not a test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is _rawDebug out of scope to fix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbergstroem I suppose not, although I'm not even sure this is a bug in _rawDebug and not an OS bug. I don't have a SmartOS machine to mess around with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to give you access if you want to tinker around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I may be in touch. (Going to focus on getting to sleep now.) BTW, it could also go the other way, I imagine, and be a "fix console.error() in this context for Windows" . If that happened, there would be no reason for _rawDebug() to exist. Of course, that might be an impossibility for all I know...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbergstroem My public keys are at https://github.com/trott.keys. What else would you need to give me access?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott ping me at bugs at bergstroem.nu or jbergstroem@irc.

@Fishrock123
Copy link
Contributor

Sounds like a _rawDebug() bug. If anything should work, it's _rawDebug().

@jbergstroem
Copy link
Member

Just to be clear then; what actually needs fixing is PrintErrorString.

@Trott
Copy link
Member Author

Trott commented Nov 3, 2015

Guess it's time for me to brush up a bit on my so-rusty-as-to-be-nonexistent C++ skillz....

SmartOS sometimes munges output from `process._rawDebug()`
but Windows can't use `console.error()` in the debug agent.
So inject logic to chose the right thing based on platform.

Fixes: nodejs#2476
@Trott
Copy link
Member Author

Trott commented Nov 4, 2015

If I change line 3066 of node.cc from...

PrintErrorString("%s\n", *message);

...to...

PrintErrorString("%s (%d bytes)\n", *message, message.length());

...and trigger the bug, the output looks like this:

Debugger listening on port 12390Debugger listening on port 12389 (32 bytes)
 (32 bytes)

The one thing this proves is that PrintErrorString() is getting called twice with the correct character strings. Otherwise, there wouldn't be two instances of (32 bytes) in the string. There would be one instance and the byte count would be around 64 bytes or so.

But how the heck are the lines getting interwoven like that?!

PrintErrorString() itself is very simple. With all the Windows stuff ifdef'ed out, it amounts to this:

static void PrintErrorString(const char* format, ...) {
  va_list ap;
  va_start(ap, format);
  vfprintf(stderr, format, ap);
  va_end(ap);
}

For fun, I tried adding fflush(stderr) after the vfprintf() call but that didn't fix anything.

My somewhat ignorant guesses are:

  • Something weird going on where a carriage return or other weird character is somehow ending up in the line causing the display to somehow munge the two lines together. This seems unlikely to me, but what do I know?
  • Some OS-specific bug or "feature" that causes stderr and/or vfprintf() to do this weirdness.

Does someone more knowledgable than me see something obvious I'm missing? I'm happy to keep pushing on this but it feels like something someone with more experience on the C++ side might see right away.

@Trott Trott added smartos Issues and PRs related to the SmartOS platform. c++ Issues and PRs that require attention from people who are familiar with C++. labels Nov 4, 2015
@Trott
Copy link
Member Author

Trott commented Nov 5, 2015

Replacing PrintErrorString() with fprintf() doesn't fix the issue. https://ci.nodejs.org/job/node-test-commit-smartos/221/nodes=smartos14-32/console

SmartOS bug/feature?

@Trott
Copy link
Member Author

Trott commented Nov 6, 2015

It looks like ultimately the problem is that stderr is unbuffered on SmartOS so we're getting some interleaving. Forcing it to line-buffering seems to fix it. Going to test some more and then submit a fix soon hopefully if the fix doesn't break a ton of other stuff in CI or something...

@Trott
Copy link
Member Author

Trott commented Nov 6, 2015

Closing in favor of #3701

@Trott Trott closed this Nov 6, 2015
Trott added a commit to Trott/io.js that referenced this pull request Nov 9, 2015
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

Fixes: nodejs#2476
Refs: nodejs#3615
Trott added a commit to Trott/io.js that referenced this pull request Nov 11, 2015
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

PR-URL: nodejs#3701
Fixes: nodejs#2476
Refs: nodejs#3615
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Trott added a commit that referenced this pull request Nov 11, 2015
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

PR-URL: #3701
Fixes: #2476
Refs: #3615
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@MylesBorins
Copy link
Contributor

removing lts-watch tag as this did not land

MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

PR-URL: #3701
Fixes: #2476
Refs: #3615
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 22, 2016
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

PR-URL: #3701
Fixes: #2476
Refs: #3615
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 2, 2016
SmartOS does not line buffer stderr by default, or at least that is the
behavior on the Node project Jenkins server. Force line buffering. This
resolves the flakiness observed on SmartOS for
test-debug-signal-cluster.

PR-URL: #3701
Fixes: #2476
Refs: #3615
Reviewed-By: Johan Bergström <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@Trott Trott deleted the smartos-flaky branch January 13, 2022 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. smartos Issues and PRs related to the SmartOS platform. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants