Got: Node.JS 12 uncaught exception on TLS error

Created on 10 Sep 2020  路  4Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: 12 (tested on v12.18.3, latest available as of today)
  • OS & version: irrelevant

Actual behavior

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.

Expected behavior

Only ERR_SSL_NO_PROTOCOLS_AVAILABLE should be emitted.

How does this apply to Got?

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.

Code to reproduce

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);
bug external nodejs bug

All 4 comments

~I cannot reproduce on RunKit~: https://runkit.com/szmarczak/5f5a30d0c15745001ab1ee69 Ah, it's v12. Yep, it's a Node.js bug.

I thought this could be fixed on Got side by forcing request.destroy() but nope :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dominusmars picture dominusmars  路  3Comments

jamestalmage picture jamestalmage  路  3Comments

lukehorvat picture lukehorvat  路  3Comments

khizarsonu picture khizarsonu  路  3Comments

framerate picture framerate  路  4Comments