Skip to content

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

Closed
indutny wants to merge 1 commit into
nodejs:v1.xfrom
indutny:fix/gh-1012
Closed

indutny wants to merge 1 commit into
nodejs:v1.xfrom
indutny:fix/gh-1012

Conversation

@indutny

@indutny indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member

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

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

cc @jbergstroem

@jbergstroem

Copy link
Copy Markdown
Member

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

@indutny

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

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

@bnoordhuis

Copy link
Copy Markdown
Member

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

@indutny

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
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.

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@indutny

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

@chrisdickinson it should not happen under test conditions.

@chrisdickinson

Copy link
Copy Markdown
Contributor

LGTM, then.

@indutny

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

@bnoordhuis LGTY too?

@bnoordhuis

Copy link
Copy Markdown
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

indutny commented Mar 3, 2015

Copy link
Copy Markdown
Member Author

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.

4 participants