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

Net: Defer reading until listeners could be added #1496

Closed
wants to merge 1 commit into from
Closed

Net: Defer reading until listeners could be added #1496

wants to merge 1 commit into from

Conversation

jameshartig
Copy link
Contributor

Defer reading until user-land has a chance to add listeners. This
allows the TLS wrapper to listen for _tlsError and trigger a
clientError event if the socket already has data that could trigger.

Fixes #1114

@mscdex mscdex added the tls Issues and PRs related to the tls subsystem. label Apr 22, 2015
@jameshartig
Copy link
Contributor Author

This also fixes nodejs/node-v0.x-archive#9355

var self = this;
process.nextTick(function() {
// Socket already has some buffered data - emulate receiving it
if (socket && socket._readableState && socket._readableState.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this has just been moved, but we really need to standardize an API for querying the size of a stream's buffer.

@jameshartig
Copy link
Contributor Author

@chrisdickinson Updated to send along this as an arg to nextTick and added a check for if (!self._handle). I also removed ended from the tests that @brendanashworth brought up. Since we're not using unref we don't need to check that it ended since the process won't die until it has.

Thanks guys for taking a look at this so quickly.

}

self.read(0);
}, this);
Copy link
Contributor

Choose a reason for hiding this comment

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

could you name this anonymous function and pull it out of the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Updated and moved into a named function above the constructor called initread

@jameshartig jameshartig changed the title Net: Defer reading until callbacks could be added Net: Defer reading until listeners could be added Apr 23, 2015
@jameshartig
Copy link
Contributor Author

@chrisdickinson I moved the anonymous function to above the constructor. Everything else look good? Thanks again!

@chrisdickinson
Copy link
Contributor

LGTM! If @indutny does not object, I'll merge this tomorrow.

@@ -199,6 +199,20 @@ function onocspresponse(resp) {
this.emit('OCSPResponse', resp);
}

function initread(tls, wrapped) {
Copy link
Member

Choose a reason for hiding this comment

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

Camel case, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I was trying to follow the function above onnewsession which was all lowercase so I thought that was the standard :/

@jameshartig
Copy link
Contributor Author

@indutny I renamed to initRead. If you want me to keep the ended var and checks in the tests, I can add those back, just let me know. Thanks

@jameshartig
Copy link
Contributor Author

@indutny would you mind taking another look after the changes I made? Thanks!

@jameshartig
Copy link
Contributor Author

Any updates @indutny @chrisdickinson ?

@indutny
Copy link
Member

indutny commented May 27, 2015

LGTM, @chrisdickinson please land!

@@ -0,0 +1,45 @@
var common = require('../common');
Copy link
Contributor

Choose a reason for hiding this comment

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

A 'use strict'; now needs to be added here with the new linter.

@jameshartig
Copy link
Contributor Author

@brendanashworth updated with 'use strict'; and linter seems to like it and tests still pass.

@chrisdickinson good to go?

@brendanashworth
Copy link
Contributor

@brendanashworth
Copy link
Contributor

hmm... the linter job failed. @fastest963 could you rebase your remote branch onto master and push to GH (preferably with a make lint beforehand)? It might need an update.

@jameshartig
Copy link
Contributor Author

@brendanashworth It looks like it failed because it couldn't find ./iojs:

[linter] $ /bin/sh -xe /tmp/hudson2733538223575635564.sh
+ NODE=/usr/local/bin/iojs make lint
gmake[1]: Entering directory '/usr/home/iojs/build/workspace/iojs+linter/nodes/linter'
./iojs tools/eslint/bin/eslint.js src lib test --reset --quiet
gmake[1]: ./iojs: Command not found
Makefile:378: recipe for target 'jslint' failed
gmake[1]: *** [jslint] Error 127
gmake[1]: Leaving directory '/usr/home/iojs/build/workspace/iojs+linter/nodes/linter'
*** Error code 2

Defer reading until user-land has a chance to add listeners. This
allows the TLS wrapper to listen for _tlsError and trigger a
clientError event if the socket already has data that could trigger.

Fixes #1114
@brendanashworth
Copy link
Contributor

I don't work on build but I think you need the recent updates to the
Makefile to lint on the CI. <surprise!> Could you rebase, then I'll try to
run it again.

Sorry about this, its a new CI setup. I'm still getting used to it.

On Monday, June 15, 2015, James Hartig notifications@github.com wrote:

@brendanashworth https://github.com/brendanashworth It looks like it
failed because of:

[linter] $ /bin/sh -xe /tmp/hudson2733538223575635564.sh

  • NODE=/usr/local/bin/iojs make lint
    gmake[1]: Entering directory '/usr/home/iojs/build/workspace/iojs+linter/nodes/linter'
    ./iojs tools/eslint/bin/eslint.js src lib test --reset --quiet
    gmake[1]: ./iojs: Command not found
    Makefile:378: recipe for target 'jslint' failed
    gmake[1]: *** [jslint] Error 127
    gmake[1]: Leaving directory '/usr/home/iojs/build/workspace/iojs+linter/nodes/linter'
    *** Error code 2


Reply to this email directly or view it on GitHub
#1496 (comment).

@jameshartig
Copy link
Contributor Author

No problem! I just rebased and pushed, want to try again? Thanks!

@brendanashworth
Copy link
Contributor

brendanashworth pushed a commit that referenced this pull request Jun 17, 2015
Defer reading until user-land has a chance to add listeners. This
allows the TLS wrapper to listen for _tlsError and trigger a
clientError event if the socket already has data that could trigger.

Fixes: #1114
PR-URL: #1496
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@brendanashworth
Copy link
Contributor

Thanks for the pull request! Landed in 061342a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Already buffered data when creating a TLSSocket doesn't trigger/throw 'error'
5 participants