-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ensure connect callback is invoked on premature socket hangup #546
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
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64d6883
Ensure connect callback is invoked on premature socket hangup
e192358
Add unit test for callback on early postgresql disconnect
d21b995
Enable the test for #534 (needs special naming)
96e4afd
Have Connection also emit 'end' on stream 'close' event
e1b1c62
Do not emit 'end' twice from Connection on close
e72aff4
Have stream emit 'close' rather than 'end' for sake of testing
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var helper = require(__dirname + '/test-helper'); | ||
var net = require('net'); | ||
var pg = require('../../..//lib/index.js'); | ||
|
||
var server = net.createServer(function(c) { | ||
console.log('server connected'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome test! Love this. 💙 |
||
c.destroy(); | ||
console.log('server socket destroyed.'); | ||
server.close(function() { console.log('server closed'); }); | ||
}); | ||
|
||
server.listen(7777, function() { | ||
console.log('server listening'); | ||
var client = new pg.Client('postgres://localhost:7777'); | ||
console.log('client connecting'); | ||
client.connect(assert.calls(function(err) { | ||
if (err) console.log("Error on connect: "+err); | ||
else console.log('client connected'); | ||
assert(err); | ||
})); | ||
|
||
}); |
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.
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.
is this TODO still needed? did you already fix this for v0.8.x and v0.10.x?
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.
On Sat, Mar 22, 2014 at 08:50:57AM -0700, Brian C wrote:
My problem was fixed and tested with both v0.8 and v0.10
The TODO is needed as it asks for an opinion from you :)
You see that both "end" and "close" events trigger "end".
Do you think that's a problem ?
Node-0.8 only sends "close".
client.js effects on 'end' are all protected by double-call
except for further sending 'end' to upper levels.
the pool calls 'destroy' and receiving 'end' from client but
is protected by the double call with this:
So is not a problem, but you migt not like the double 'end'
event anyway.
--strk;
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.
Thanks for the explanation! Yeah, definitely emitting end twice would be something to avoid. I don't think it should be too hard, just have a like 'this._ended' flag or something on the client, set it the first time, and check if it's set & don't emit. What you think?
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.
Sure, that's ok for me, but I'm going to do it myself, do you mind ?
I've seen it used already for the connection object, so maybe you could
reuse an existing flag or something like that... It was called _ending
or _closing or something similar...
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.
In v0.10 and forward
'end'
means the readable stream has receivedEOF
,'close'
means the underlying resource (socket/fd) has been closed. It should only be necessary to listen to'close'
.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.
Thank you. It should be tested with node-0.8 if only listening for "close" is ok.
I guess we'd still need to emit "end" to maintain compatibility in the higher levels.
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.
I think only listening for
close
is okay. As long as we don't emitend
twice and it works on v0.8 and v0.10 I'm cool with it. Lemme know when you're ready for another 🔍 and hopefully a merge!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.
I've pushed a commit for only listening on 'close'. Tested locally with node 0.8.9, 0.8.25 and 0.10.26