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 — test: fix flaky test-net-socket-local-address by Trott · Pull Request #4644 · nodejs/node

Conversation

@Trott

@Trott Trott commented Jan 12, 2016

Copy link
Copy Markdown
Member

The close event can fire twice if close is called twice. Move checks
to exit event for process instead.

Ref: #4476

Sorry, something went wrong.

Uh oh!

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

All reactions
@Trott
test: fix flaky test-net-socket-local-address
66e0f79
The close event can fire twice if close is called twice. Move checks
to exit event for process instead.

Ref: nodejs#4476
@Trott Trott added the test Issues and PRs related to Node.js core tests and test infrastructure. label Jan 12, 2016
@Trott

Trott commented Jan 12, 2016

Copy link
Copy Markdown
Member Author

Stress CI without the fix: https://ci.nodejs.org/job/node-stress-single-test/334/nodes=win-vs2015/console

Stress CI with this fix: https://ci.nodejs.org/job/node-stress-single-test/337/nodes=win-vs2015/console

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott Trott mentioned this pull request Jan 12, 2016
test: enable parallel testing in test-ci #4476
Closed
@jbergstroem

jbergstroem commented Jan 12, 2016

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

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

@mscdex mscdex added the net Issues and PRs related to the net subsystem. label Jan 12, 2016
mscdex
mscdex reviewed Jan 12, 2016
View reviewed changes
Comment thread test/parallel/test-net-socket-local-address.js

@mscdex mscdex Jan 12, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Couldn't this be changed to common.mustCall(fn, 2) instead?

Sorry, something went wrong.

Uh oh!

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

All reactions

@Trott Trott Jan 12, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not as the test was written. Most of the times, it would run once, but every once in a while on Windows (and possibly elsewhere, but definitely on Windows), it would run twice.

In a stress test run, the test ran 9999 times on Windows. 9988 times, the function ran once. But 11 times, the test failed because it ran twice.

Sorry, something went wrong.

Uh oh!

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

All reactions
@cjihrig

cjihrig commented Jan 12, 2016

Copy link
Copy Markdown
Contributor

Changes LGTM, but shouldn't we be able to reliably determine how many times the close event occurs?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott

Trott commented Jan 12, 2016

Copy link
Copy Markdown
Member Author

@cjihrig My original fix for this was to put in a boolean that indicated whether or not server.close() had been called yet and to check that boolean right before calling server.close(). This way, we could avoid the infrequent (but still occurring from time to time) situation where server.close() gets called by two different invocations of testConnect().

I refactored it to process.on('exit',...) because the resulting code is simpler this way and the change set is more straightforward as well.

The race condition exists because the client connection callback calls testConnect() (where server.close() happens) asynchronously (in the callback to client.close()) while the server calls it synchronously in its connection callback. If, at the end of the test, the client close callback manages to invoke testConnect() after the server has done so but before the program actually exits, then the close callback will fire twice. At least, that was my theory which appears to be borne out by the stress test results above.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cjihrig cjihrig mentioned this pull request Jan 12, 2016
test: fix flaky test-net-socket-local-address #4650
Closed
@cjihrig

cjihrig commented Jan 12, 2016

Copy link
Copy Markdown
Contributor

@Trott would you mind taking a look at #4650. IMO, this test is overly complicated. It's calling testConnect() from everywhere, including multiple server events. I tried to simplify it in #4650.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jasnell jasnell added the lts-watch-v4.x label Jan 12, 2016
@Trott

Trott commented Jan 13, 2016

Copy link
Copy Markdown
Member Author

@cjihrig Took a look. It looked good, but when I tried to confirm that it still triggered an assertion in Node 3.0.0 (by converting ES6 stuff to ES5), the test passed instead. So it no longer tests for the bug it was written to find.

Then it occurred to me that I didn't do a similar thing for this version of the test in this PR. So I've done that now and I can report that it still triggers the error:

$ node test/parallel/test-net-socket-local-address.js 

assert.js:89
  throw new assert.AssertionError({
  ^
AssertionError: client and server should agree on the ports used
    at process.<anonymous> (/Users/trott/io.js/test/parallel/test-net-socket-local-address.js:43:10)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)

So that's good. For the record, here's the version of the test in this PR with unsupported-in-3.0.0 features rewritten or commented out:

'use strict';
// const common = require('../common');
const assert = require('assert');
const net = require('net');

// skip test in FreeBSD jails
// if (common.inFreeBSDJail) {
//   console.log('1..0 # Skipped: In a FreeBSD jail');
//   return;
// }

var conns = 0;
var clientLocalPorts = [];
var serverRemotePorts = [];

const server = net.createServer(function(socket) {
  serverRemotePorts.push(socket.remotePort);
  testConnect();
});

const client = new net.Socket();

server.listen(12346, '127.0.0.1', testConnect);

function testConnect() {
  if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) {
    // We're waiting for a callback to fire.
    return;
  }

  if (conns === 2) {
    return server.close();
  }
  client.connect(12346, '127.0.0.1', function() {
    clientLocalPorts.push(this.localPort);
    this.once('close', testConnect);
    this.destroy();
  });
  conns++;
}

process.on('exit', function() {
  assert.deepEqual(clientLocalPorts, serverRemotePorts,
                   'client and server should agree on the ports used');
  assert.equal(2, conns);
});

If you can come up with a simpler test in that other PR that still finds the bug the test was written for, I'm happy to go with that instead of this PR, of course.

All reactions

Sorry, something went wrong.

Uh oh!

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

cjihrig added a commit that referenced this pull request Jan 13, 2016
@cjihrig
test: fix flaky test-net-socket-local-address
6cfd0b5
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: #4476
Refs: #4644
PR-URL: #4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@cjihrig

cjihrig commented Jan 13, 2016

Copy link
Copy Markdown
Contributor

Closing in favor of #4650.

All reactions

Sorry, something went wrong.

Uh oh!

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

@cjihrig cjihrig closed this Jan 13, 2016
rvagg pushed a commit that referenced this pull request Jan 14, 2016
@cjihrig @rvagg
test: fix flaky test-net-socket-local-address
525afc1
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: #4476
Refs: #4644
PR-URL: #4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@MylesBorins MylesBorins added test Issues and PRs related to Node.js core tests and test infrastructure. and removed lts-watch-v4.x test Issues and PRs related to Node.js core tests and test infrastructure. labels Jan 28, 2016
MylesBorins pushed a commit that referenced this pull request Jan 28, 2016
@cjihrig Myles Borins
test: fix flaky test-net-socket-local-address
405a8d6
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: #4476
Refs: #4644
PR-URL: #4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 11, 2016
@cjihrig Myles Borins
test: fix flaky test-net-socket-local-address
5f9345a
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: #4476
Refs: #4644
PR-URL: #4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Feb 11, 2016
@cjihrig Myles Borins
test: fix flaky test-net-socket-local-address
0462b78
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: nodejs#4476
Refs: nodejs#4644
PR-URL: nodejs#4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Feb 15, 2016
@cjihrig Myles Borins
test: fix flaky test-net-socket-local-address
d615757
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: nodejs#4476
Refs: nodejs#4644
PR-URL: nodejs#4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
@cjihrig Michael Scovetta
test: fix flaky test-net-socket-local-address
f3778e1
Prior to this commit, the test was flaky because it was
executing the majority of its logic in a function called from
the client and multiple events on the server. This commit
simplifies the test by separating the server's connection and
listening events, and isolating the client logic.

Refs: nodejs#4476
Refs: nodejs#4644
PR-URL: nodejs#4650
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@Trott
Trott deleted the fix-net-socket-local-address branch January 13, 2022 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

net Issues and PRs related to the net subsystem. test Issues and PRs related to Node.js core tests and test infrastructure.

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.

6 participants

@Trott @jbergstroem @cjihrig @mscdex @jasnell @MylesBorins
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.