Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream_wrap: add HandleScope's in uv callbacks #1078

Closed
wants to merge 4 commits into from

Conversation

indutny
Copy link
Member

@indutny indutny commented Mar 5, 2015

Ensure that no handles will leak into global HandleScope by adding
HandleScope's in all JS-calling libuv callbacks in stream_wrap.cc.

Fix: #1075

NOTE: WIP

Ensure that no handles will leak into global HandleScope by adding
HandleScope's in all JS-calling libuv callbacks in `stream_wrap.cc`.

Fix: nodejs#1075
indutny added 3 commits March 5, 2015 20:26
Don't forget to call `MakeWeak` to ensure that instance objects are
garbage collectable.
Hold non-persistent reference in JS, rather than in C++ to avoid cycles.
Ensure no persistent-induced loops in C++-land by storing
`SecureContext` reference in JS-land.
@indutny
Copy link
Member Author

indutny commented Mar 6, 2015

Seems to be fixing the issue, cc @bnoordhuis

@indutny
Copy link
Member Author

indutny commented Mar 6, 2015

cc @iojs/crypto

@@ -229,6 +232,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle,
const uv_buf_t* buf,
uv_handle_type pending) {
StreamWrap* wrap = static_cast<StreamWrap*>(handle->data);
HandleScope scope(wrap->env()->isolate());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this HandleScope do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Captures all handles in this libuv callback? OnReadCommon calls OnRead() which might create handles.

@bnoordhuis
Copy link
Member

LGTM with comments. I don't have time to test right now but this fixes all the test failures when you throw an CHECK_EQ(number_of_handles, HandleScope::NumberOfHandles(isolate)) in the main loop?

@indutny
Copy link
Member Author

indutny commented Mar 6, 2015

Yep, it fixes all handle leaks.

indutny added a commit that referenced this pull request Mar 6, 2015
Ensure that no handles will leak into global HandleScope by adding
HandleScope's in all JS-calling libuv callbacks in `stream_wrap.cc`.

Fix: #1075
PR-URL: #1078
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
indutny added a commit that referenced this pull request Mar 6, 2015
Don't forget to call `MakeWeak` to ensure that instance objects are
garbage collectable.

PR-URL: #1078
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
indutny added a commit that referenced this pull request Mar 6, 2015
Hold non-persistent reference in JS, rather than in C++ to avoid cycles.

PR-URL: #1078
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@indutny
Copy link
Member Author

indutny commented Mar 6, 2015

Landed in 583a868, dccb69a, c09c90c. Thank you!

@indutny indutny closed this Mar 6, 2015
@indutny indutny deleted the fix/gh-1075 branch March 6, 2015 16:06
rvagg added a commit that referenced this pull request Mar 6, 2015
Notable changes:

* buffer: New `Buffer#indexOf()` method, modelled off `Array#indexOf()`.
  Accepts a String, Buffer or a Number. Strings are interpreted as UTF8.
  (Trevor Norris) #561
* fs: `options` object properties in `'fs'` methods no longer perform a
  `hasOwnProperty()` check, thereby allowing options objects to have
  prototype properties that apply. (Jonathan Ong)
  #635
* tls: A likely TLS memory leak was reported by PayPal. Some of the recent
  changes in stream_wrap appear to be to blame. The initial fix is in
  #1078, you can track the progress
  toward closing the leak at
  #1075 (Fedor Indutny).
* npm: Upgrade npm to 2.7.0. See npm CHANGELOG.md:
  https://github.com/npm/npm/blob/master/CHANGELOG.md#v270-2015-02-26
  for details including why this is a semver-minor when it could have
  been semver-major.
* TC: Colin Ihrig (@cjihrig) resigned from the TC due to his desire to do
  more code and fewer meetings.
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.

2 participants