Node.JS behavior: on some kind of errors (in this example ERR_SSL_NO_PROTOCOLS_AVAILABLE) the 'error' event on a https request (due to the TLS socket) is fired 2 times, the first is ERR_SOCKET_CLOSED the second one is ERR_SSL_NO_PROTOCOLS_AVAILABLE. The correct one should be the latter, while the first error code makes sense, it's too generic.
Only ERR_SSL_NO_PROTOCOLS_AVAILABLE should be emitted.
Got only listen for the first 'error' event, for some reason I've not yet investigated it ignore ERR_SOCKET_CLOSED. ERR_SSL_NO_PROTOCOLS_AVAILABLE end up as a uncaught exception.
Below 2 examples one with "pure" Node.JS and the other with Got.
After the two examples a simple server example can be found.
Node.JS client
const https = require('https');
const req = https.request('https://127.0.0.1:9999', {
maxVersion: 'TLSv1.1',
});
req.on('error', (e) => {
console.error(e);
});
req.end();
Got client
const got = require('got');
const request = got.stream('https://127.0.0.1:9999', {
maxVersion: 'TLSv1.1',
});
request.on('error', (error) => {
console.log(error);
});
Server
const https = require('https');
const server = https.createServer({
minVersion: 'TLSv1.2',
});
server.listen(9999);
~I cannot reproduce on RunKit~: https://runkit.com/szmarczak/5f5a30d0c15745001ab1ee69 Ah, it's v12. Yep, it's a Node.js bug.
You may want to file an issue at https://github.com/nodejs/node/issues/new?template=1-bug-report.md
I thought this could be fixed on Got side by forcing request.destroy() but nope :(