tls: emit errors happening before handshake finish
authorMalte-Thorben Bruns <skenqbx@gmail.com>
Fri, 22 May 2015 19:12:59 +0000 (21:12 +0200)
committerFedor Indutny <fedor@indutny.com>
Fri, 22 May 2015 19:30:22 +0000 (21:30 +0200)
commit2a71f02988244b6299db8fe8ba3cc0491793acfc
treeab902f89347410a9b6e429db2827d5af00e61a9d
parent2bb2f06b3e53ca44687afdaa9b833e0b6181ff76
tls: emit errors happening before handshake finish

This fixes a race condition introduced in 80342f6.
`socket.destroy(err)` only emits the passed error when
`socket._writableState.errorEmitted === false`, `ssl.onerror`
sets `errorEmitted = true` just before calling
`socket.destroy()`.

See: https://github.com/nodejs/io.js/issues/1119
See: https://github.com/nodejs/io.js/issues/1711
PR-URL: https://github.com/nodejs/io.js/pull/1769
Reviewed-By: Fedor Indutny <fedor@indutny.com>
lib/_tls_wrap.js
test/parallel/test-tls-handshake-error.js [new file with mode: 0644]