Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: fix re-entrancy issue with TLS close_notify
OpenSSL's API requires SSL_get_error be called immediately after the failing operation, otherwise the SSL object may have changed state and no longer report information about the failing error. TLSWrap almost heeds this rule, except in TLSWrap::ClearOut. If SSL_read picks up a close_notify (detected by checking SSL_get_shutdown), Node calls out to JS with EmitRead(UV_EOF) and only afterwards proceeds to dispatch on the error. But, by this point, Node has already re-entered JS and indeed JS seems to sometimes call back into TLSWrap::DoShutdown, calling SSL_shutdown. (I think this comes from onStreamRead in stream_base_commons.js?) Instead, SSL_get_error and the error queue should be sampled earlier. This avoids the issue worked around by nodejs#1661, where GetSSLError needed to check if ssl_ was destroyed before calling SSL_get_error. We can now remove that wrapper and just call SSL_get_error directly. (Any case where ssl_ may be destroyed first is a case where ssl_ may change state, so it's a bug either way.) This is the first of two fixes in error-handling here. The EmitRead(UV_EOF) seems to additionally swallow fatal alerts from the peer. Some of the ECONNRESET expectations in the tests aren't actually correct. The next commit will fix this as well.
- Loading branch information