tls: emit errors happening before handshake's finish
This fixes a race condition introduced in 80342f64.
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 & https://github.com/nodejs/io.js/pull/1711
/cc @indutny