Skip to content

Commit

Permalink
net: ensure Write/ShutdownWrap references handle
Browse files Browse the repository at this point in the history
`StreamBase::AfterWrite` is passing handle as an argument to the
`afterWrite` function in net.js. Thus GC should not collect the handle
and the request separately and assume that they are tied together.

With this commit - request will always outlive the StreamBase instance,
helping us survive the GC pass.

Same applies to the ShutdownWrap instances, they should never be
collected after the StreamBase instance.

Fix: #1580
PR-URL: #1590
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
indutny committed May 3, 2015
1 parent 2a3a190 commit b4f5898
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function onSocketFinish() {

var req = new ShutdownWrap();
req.oncomplete = afterShutdown;
req.handle = this._handle;
var err = this._handle.shutdown(req);

if (err)
Expand Down Expand Up @@ -627,6 +628,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
}

var req = new WriteWrap();
req.handle = this._handle;
req.oncomplete = afterWrite;
req.async = false;
var err;
Expand Down

0 comments on commit b4f5898

Please sign in to comment.