Skip to content

tls: emit errors on close whilst async action - #1702

Closed
indutny wants to merge 3 commits into
nodejs:masterfrom
indutny:fix/gh-node-8780
Closed

tls: emit errors on close whilst async action#1702
indutny wants to merge 3 commits into
nodejs:masterfrom
indutny:fix/gh-node-8780

Conversation

@indutny

Copy link
Copy Markdown
Member

When loading session, OCSP response, SNI, always check that the
self._handle is present. If it is not - the socket was closed - and we
should emit the error instead of throwing an uncaught exception.

Fix: nodejs/node-v0.x-archive#8780
Fix: #1696

@indutny

Copy link
Copy Markdown
MemberAuthor

cc @iojs/crypto

@migounette

Copy link
Copy Markdown

@indutny You fixed at the JS part by checking the _handle, but what I found during an intensive play with TLS is that the _encout was NULL (a C++ level). It is a kind of SSL Close issue race condition (for me), but I need to change the test case because it's very difficult for me to reproduce.

Thanks for the fix

@mscdexmscdex added the tls Issues and PRs related to the tls subsystem. label May 14, 2015
@indutny

Copy link
Copy Markdown
MemberAuthor

@migounette@EricTheOne: I have updated the PR, please take a look

@EricTheOne

Copy link
Copy Markdown

@indutny thanks, applied both patches in order on v2.0.2, getting a segfault elsewhere (maybe it's progress):

Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000d18d00 in node::StreamBase::EmitData(long, v8::Local<v8::Object>, v8::Local<v8::Object>) ()
(gdb) bt
#0 0x0000000000d18d00 in node::StreamBase::EmitData(long, v8::Local<v8::Object>, v8::Local<v8::Object>) ()
#1 0x0000000000d3cc8a in node::TLSWrap::OnReadSelf(long, uv_buf_t const*, uv_handle_type, void*) ()
#2 0x0000000000d40d19 in node::TLSWrap::OnReadImpl(long, uv_buf_t const*, uv_handle_type, void*) ()
#3 0x000000000084fa02 in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#4 0x0000000000876c1b in v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) ()

@indutny

Copy link
Copy Markdown
MemberAuthor

@EricTheOne pushed one more commit, PTAL

@EricTheOne

Copy link
Copy Markdown

@indutny I've applied all three commits in order, on v2.0.2. Getting a different segfault now:

Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000030f1490 in ?? ()
(gdb) bt
#0 0x00000000030f1490 in ?? ()
#1 0x0000000000d40d29 in node::TLSWrap::OnReadImpl(long, uv_buf_t const*, uv_handle_type, void*) ()
#2 0x000000000084fa02 in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) ()
#3 0x0000000000876c1b in v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) ()

@indutny

Copy link
Copy Markdown
MemberAuthor

@EricTheOne looks like I don't fully understand problem yet. Any way I can reproduce it locally?

@indutny

Copy link
Copy Markdown
MemberAuthor

Just a heads up, @evanlucas discovered a crash in a test: https://gist.github.com/evanlucas/6ab0a62ebe7ffa5d0ddf

It is reproducible after patching the test suite:

diff --git a/test/parallel/test-tls-js-stream.js b/test/parallel/test-tls-js-stream.js
index e156f44..292bd4f 100644
--- a/test/parallel/test-tls-js-stream.js+++ b/test/parallel/test-tls-js-stream.js@@ -61,6 +61,7 @@ var server = tls.createServer({
socket.end('hello');
socket.resume();
+ socket.destroy();
});
socket.once('close', function() {

Going to investigate it in detail later.

@indutny

Copy link
Copy Markdown
MemberAuthor

@evanlucas and it is actually fixed by this commit ad3a799

@indutny

Copy link
Copy Markdown
MemberAuthor

Erm, not by commit, rather by this PR.

@evanlucas

Copy link
Copy Markdown
Contributor

yay!

@indutny

Copy link
Copy Markdown
MemberAuthor

Which is kind of sad for the @EricTheOne's thing...

@indutny

Copy link
Copy Markdown
MemberAuthor

indutny added 3 commits June 1, 2015 18:34
When loading session, OCSP response, SNI, always check that the
`self._handle` is present. If it is not - the socket was closed - and we
should emit the error instead of throwing an uncaught exception.
Fix: nodejs/node-v0.x-archive#8780Fix: nodejs#1696
* Destroy `SSL*` and friends on a next tick to make sure that we are not
doing it in one of the OpenSSL callbacks
* Add more checks to the C++ methods that might be invoked during
destructor's pending queue cleanup
Fix: nodejs/node-v0.x-archive#8780Fix: nodejs#1696
@indutny

Copy link
Copy Markdown
MemberAuthor

@migounette@EricTheOne any news? ;)

@indutny

Copy link
Copy Markdown
MemberAuthor

@indutny

Copy link
Copy Markdown
MemberAuthor

CI is green.

@trevnorris

Copy link
Copy Markdown
Contributor

@indutny going to merge this?

@indutny

Copy link
Copy Markdown
MemberAuthor

Yeah, let's land it. @trevnorris LGTY?

@trevnorris

Copy link
Copy Markdown
Contributor

LGTM

indutny added a commit that referenced this pull request Jun 4, 2015
When loading session, OCSP response, SNI, always check that the
`self._handle` is present. If it is not - the socket was closed - and we
should emit the error instead of throwing an uncaught exception.
Fix: nodejs/node-v0.x-archive#8780Fix: #1696
PR-URL: #1702
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this pull request Jun 4, 2015
* Destroy `SSL*` and friends on a next tick to make sure that we are not
doing it in one of the OpenSSL callbacks
* Add more checks to the C++ methods that might be invoked during
destructor's pending queue cleanup
Fix: nodejs/node-v0.x-archive#8780Fix: #1696
PR-URL: #1702
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
indutny added a commit that referenced this pull request Jun 4, 2015
PR-URL: #1702
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@indutny

Copy link
Copy Markdown
MemberAuthor

Landed in 5795e83, 75930bb, and 59d9734. Thank you!

@rvaggrvagg mentioned this pull request Jun 11, 2015
@indutny
indutny deleted the fix/gh-node-8780 branch June 21, 2015 01:49
Comment threadsrc/tls_wrap.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if the error message sounds like a TypeError

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, I think it is worth submitting a follow-up fix PR. ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@indutny I feel that the default types of Errors is not enough. We should at least have something like ValueError. What do you think?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I'd say it might be too expensive to create them in C++, unless I'm missing something obvious.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I locally created a patch which fixes all the inconsistent error messages like this, in the js files. And I had an internal/errors.js file which defined ValueError. Looks like that solves most of the wrong data error messages. But I am not sure if it is worthy introducing a new Error type.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, I don't think anyone really checks the type of error. It kind of serves only an informational purpose when it pops up in the stderr.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tlsIssues and PRs related to the tls subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

segfault in TLS Segfault node v0.11.14 related to TLS

8 participants

@indutny@migounette@EricTheOne@evanlucas@trevnorris@thefourtheye@mscdex@brendanashworth