From b4f58983952fb56262795893b4f7b0482d1256f2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <fedor@indutny.com> Date: Sat, 2 May 2015 17:32:29 +0200 Subject: [PATCH] net: ensure Write/ShutdownWrap references handle `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: https://github.com/iojs/io.js/pull/1580 PR-URL: https://github.com/iojs/io.js/pull/1590 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> --- lib/net.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/net.js b/lib/net.js index 867e1df7ccc252..df3c3d328afb3a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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) @@ -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;