Skip to content

Commit

Permalink
tls: do not wrap net.Socket with StreamWrap
Browse files Browse the repository at this point in the history
Fixes: nodejs#3655
PR-URL: nodejs#12799
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
krydos authored and Olivier Martin committed May 19, 2017
1 parent bb794fb commit 651e96c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const util = require('util');
const common = require('_tls_common');
const StreamWrap = require('_stream_wrap').StreamWrap;
const Buffer = require('buffer').Buffer;
const Duplex = require('stream').Duplex;
const debug = util.debuglog('tls');
const Timer = process.binding('timer_wrap').Timer;
const tls_wrap = process.binding('tls_wrap');
Expand Down Expand Up @@ -275,12 +274,10 @@ function TLSSocket(socket, options) {

// Wrap plain JS Stream into StreamWrap
var wrap;
if (!(socket instanceof net.Socket) && socket instanceof Duplex)
wrap = new StreamWrap(socket);
else if ((socket instanceof net.Socket) && !socket._handle)
wrap = new StreamWrap(socket);
else
if ((socket instanceof net.Socket && socket._handle) || !socket)
wrap = socket;
else
wrap = new StreamWrap(socket);

// Just a documented property to make secure sockets
// distinguishable from regular ones.
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-tls-wrap-event-emmiter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

/*
* Issue: https://github.com/nodejs/node/issues/3655
* Test checks if we get exception instead of runtime error
*/

require('../common');
const assert = require('assert');

const TlsSocket = require('tls').TLSSocket;
const EventEmitter = require('events').EventEmitter;
assert.throws(
() => { new TlsSocket(new EventEmitter()); },
/^TypeError: this\.stream\.pause is not a function/
);

0 comments on commit 651e96c

Please sign in to comment.