Skip to content

Fix network partition test race #1677

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

Merged
merged 1 commit into from
Jun 25, 2018

Conversation

sehrope
Copy link
Contributor

@sehrope sehrope commented Jun 16, 2018

Fixes a race condition in the network partition test that was repeatedly popping up on older (slower!) versions of node. You can simulate the race condition more easily by dropping the timeout from 50 ms to 1 ms. Here's the error:

network-partition-tests.js
  readyForQuery server Message: Cannot read property 'destroy' of undefined
TypeError: Cannot read property 'destroy' of undefined
    at Server.drop (/home/travis/build/sehrope/node-postgres/test/integration/client/network-partition-tests.js:49:14)
    at Timeout._onTimeout (/home/travis/build/sehrope/node-postgres/test/integration/client/network-partition-tests.js:70:14)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)

First commit changes the dummy server to only issue the destroy if the socket exists.

Second commit changes the test harness to wait for the connection event on the server prior to issuing the destroy.

@@ -46,7 +46,9 @@ Server.prototype.start = function (cb) {
}

Server.prototype.drop = function () {
this.socket.destroy()
if (this.socket) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this check still necessary after the second change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose not as the test server is only used in that one file and the drop is now invoked only after a connection is established. Order of addition was "Hey let's get rid of this error first...", hence the two commits though I guess it's pointless (and harmless).

Copy link
Collaborator

@charmander charmander left a comment

Choose a reason for hiding this comment

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

Would still suggest removing the check in the interest of avoiding dead code, though; not checking won’t cause any silent problems.

@sehrope sehrope force-pushed the fix-network-partition-test-race branch from cafbbe0 to 2dc5c68 Compare June 17, 2018 15:58
@sehrope
Copy link
Contributor Author

sehrope commented Jun 17, 2018

Good point. I've removed the first commit. If we ever change things to use this test server elsewhere we can address things like that.

@charmander charmander merged commit 1cbd507 into brianc:master Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants