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

test: fix racey-ness in tls-inception #1040

Closed
wants to merge 1 commit into from

Conversation

indutny
Copy link
Member

@indutny indutny commented Mar 3, 2015

Fix test failure on FreeBSD and SmartOS, which happens due to a bad
timing:

events.js:141
      throw er; // Unhandled 'error' event
            ^
Error: read ECONNRESET
    at exports._errnoException (util.js:734:11)
    at TLSWrap.onread (net.js:538:26)

The outer net.conncet() socket stays alive after the inner socket is
gone. This happens because .pipe()'s implementation does not destroy
the source side when the destination has emitted close.

Fix: #1012

Fix test failure on FreeBSD and SmartOS, which happens due to a bad
timing:

    events.js:141
          throw er; // Unhandled 'error' event
                ^
    Error: read ECONNRESET
        at exports._errnoException (util.js:734:11)
        at TLSWrap.onread (net.js:538:26)

The outer `net.conncet()` socket stays alive after the inner socket is
gone. This happens because `.pipe()`'s implementation does not `destroy`
the source side when the destination has emitted `close`.

Fix: nodejs#1012
@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

cc @jbergstroem

@jbergstroem
Copy link
Member

Confirmed that the patch indeed fixes the race on FreeBSD and SmartOS (solaris). Thanks, @indutny.

@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

Good! Please review, @iojs/crypto @iojs/collaborators

@bnoordhuis
Copy link
Member

If calling socket.destroy() explicitly on close fixes it, doesn't that suggest there's a streams bug somewhere? /cc @chrisdickinson.

@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

@bnoordhuis it might be that the socket was closed without sending the shutdown on it. At least it doesn't get EOF event, so here we have ECONNRESET.

@chrisdickinson
Copy link
Contributor

"close" and "destroy" are pretty underspecified per base streams. "close" will unpipe any upstream stream from the emitter. If a streams1 stream is the emitter, it will attempt to call destroy on any downstream streams.


dest.on('close', function() {
socket.destroy();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! that's the problem. dest is a streams3 stream, which does not call destroy on downstream streams on close. streams1 streams would call destroy on downstream streams.

@chrisdickinson
Copy link
Contributor

I guess my only remaining question is: should we set up socket.on('close', ()=> { dest.destroy(); }) as well?

@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

@chrisdickinson it should not happen under test conditions.

@chrisdickinson
Copy link
Contributor

LGTM, then.

@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

@bnoordhuis LGTY too?

@bnoordhuis
Copy link
Member

Um, I suppose so. @chrisdickinson's explanation about streams1 vs. streams3 objects makes it sound like there is a loaded gun waiting to blow off the feet of anyone mixing them in an application. I find it slightly worrying.

indutny added a commit that referenced this pull request Mar 3, 2015
Fix test failure on FreeBSD and SmartOS, which happens due to a bad
timing:

    events.js:141
          throw er; // Unhandled 'error' event
                ^
    Error: read ECONNRESET
        at exports._errnoException (util.js:734:11)
        at TLSWrap.onread (net.js:538:26)

The outer `net.conncet()` socket stays alive after the inner socket is
gone. This happens because `.pipe()`'s implementation does not `destroy`
the source side when the destination has emitted `close`.

Fix: #1012
PR-URL: #1040
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
@indutny
Copy link
Member Author

indutny commented Mar 3, 2015

Landed in e1bf670, thank you!

@indutny indutny closed this Mar 3, 2015
@indutny indutny deleted the fix/gh-1012 branch March 3, 2015 21:08
@rvagg rvagg mentioned this pull request Mar 4, 2015
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.

None yet

4 participants