Description
Version
16.13.2
Platform
Darwin Kernel Version 20.6.0
Subsystem
No response
What steps will reproduce the bug?
Run the client code with Node.js v16:
const https = require('https');
const req = https.request('https://stage1trustifieventsbackend.herokuapp.com', {
method: 'POST',
rejectUnauthorized: false
}, (res) => {
res.on('data', d => {
console.log(d.toString());
});
}).on('error', error => {
console.error(error);
});
req.write('');
req.end();
How often does it reproduce? Is there a required condition?
The code works well when it is run against AWS EC2 backend by both Nodejs v14/v16 clients and when it is run against Heroku backend (stack 20) by the Nodejs v14 client.
This request also works well when it is run by the Postman app.
This code fails only when it is run against Heroku (stack 20) server by the Nodejs v16 client.
The Heroku point is that its servers run unsecure on the port "80" and the Heroku itself translates http requests to https.
I think the issue here is in the Heroku SSL certificates that become incompatible to the nodejs client.
What is the difference between v14/v16 https
library? How this issue can be debugged?
What is the expected behavior?
Return 200 status.
What do you see instead?
Error: socket hang up
at connResetException (node:internal/errors:691:14)
at TLSSocket.socketOnEnd (node:_http_client:471:23)
at TLSSocket.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1343:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Additional information
The server-side code is:
const express = require('express');
const app = express();
app.use((req, res, next) => {
console.log('request received');
setTimeout(function () {
res.writeProcessing();
}, 1000);
setTimeout(function () {
res.writeProcessing();
}, 2000);
setTimeout(function () {
res.status(200).send({value:'ok'});
}, 3000);
});
const port = process.env.PORT || 8080;
app.listen(port, function () {
console.log('server started');
});