Skip to content

Instantly share code, notes, and snippets.

@kbirger
Created April 26, 2022 13:55
Show Gist options
  • Save kbirger/8b17b62bc042c9022ff64deda96914e6 to your computer and use it in GitHub Desktop.
Save kbirger/8b17b62bc042c9022ff64deda96914e6 to your computer and use it in GitHub Desktop.
EPROTO TLS error reproduction using `https` package
// Tested on nodejs 14 and 16.14.2
// axios 0.26.1
//
// USAGE
// save to a folder as index.js
// run `npm init -y && npm install axios`
// run `node test-axios.js ` for reproduction with axios
const axios = require('axios');
const mocklabHost = 'https://4g73r.mocklab.io'; // any mock with a /hello endpoint
const axiosInstance = axios.create({
baseURL: `${mocklabHost}`,
responseType: 'json',
});
async function main() {
try {
await Promise.all([
axiosInstance.get('/hello'),
axiosInstance.get('/hello')
]);
} catch (error) {
console.log(error.message);
// uncomment for more info, possibly
// this is commented because the error object can be so long
// that it prevents seeing the error message in some terminals
// throw error;
}
}
(async () => {
for (let i = 0; i < 20; i++) {
await main();
await new Promise(resolve => setTimeout(resolve, 1000));
}
})();
// Tested on nodejs 14 and 16.14.2
//
// USAGE
// save to a folder as test-https.js
// run `node test-https.js` for reproduction with `https` library
const https = require('https');
const mocklabHost = 'https://4g73r.mocklab.io'; // any mock with a /hello endpoint
function makeHttpsPromise() {
return new Promise((resolve, reject) => {
https.get(new URL(`${mocklabHost}/hello`), (res) => {
res.on('data', () => {})
res.on('close', () => {
if (res.statusCode !== 200) {
reject(res)
} else {
resolve(res);
}
})
}).on('error', (e) => {
reject(e)
});
});
}
async function main() {
try {
await Promise.all([
makeHttpsPromise(),
makeHttpsPromise()
]);
} catch (error) {
console.log(error.message);
// uncomment for more info, possibly
// this is commented because the error object can be so long
// that it prevents seeing the error message in some terminals
// throw error;
}
}
(async () => {
for (let i = 0; i < 20; i++) {
await main();
await new Promise(resolve => setTimeout(resolve, 1000));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment