Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
tls: set _connecting before starting the flow
Browse files Browse the repository at this point in the history
When creating a TLSSocket instance based on the existing connecting
socket, `_connecting` property is copied after the initialization of
`net.Socket`. However, since `net.Socket` constructor will call
`.read(0)` if the `readable` is true - error may happen at this code
chunk in net.js:

    Socket.prototype._read = function(n) {
      debug('_read');

      if (this._connecting || !this._handle) {
        debug('_read wait for connection');
        this.once('connect', this._read.bind(this, n));
    ...

Leading to a test failures on windows:

 - test/simple/test-tls-connect-given-socket.js

Signed-off-by: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
indutny committed Apr 17, 2014
1 parent 2c6b424 commit 77d1f4a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ function TLSSocket(socket, options) {
net.Socket.call(this, {
handle: socket && socket._handle,
allowHalfOpen: socket && socket.allowHalfOpen,
readable: true,
writable: true
readable: false,
writable: false
});

// To prevent assertion in afterConnect()
Expand Down Expand Up @@ -210,6 +210,12 @@ function TLSSocket(socket, options) {
} else {
this._init(socket);
}

// Make sure to setup all required properties like: `_connecting` before
// starting the flow of the data
this.readable = true;
this.writable = true;
this.read(0);
}
util.inherits(TLSSocket, net.Socket);
exports.TLSSocket = TLSSocket;
Expand Down

0 comments on commit 77d1f4a

Please sign in to comment.