-
-
Notifications
You must be signed in to change notification settings - Fork 32
RangeError: Invalid time value #24
Comments
That code will crash. |
I'm receving a same error when I do the second request, but works normally at first request |
@gabrieldissotti Can you please provide a sample of your code? |
@gabrieldissotti I solve this issue, just compile from ts to js. import * as https from "https";
const checkPort = port => !Number.isNaN(parseFloat(port)) && Math.sign(port) === 1;
const getDaysBetween = (validFrom, validTo) => Math.round(Math.abs(+validFrom - +validTo) / 8.64e7);
const getDaysRemaining = (validFrom, validTo) => {
const daysRemaining = getDaysBetween(validFrom, validTo);
if (new Date(validTo).getTime() < new Date().getTime()) {
return -daysRemaining;
}
return daysRemaining;
};
const sslChecker = ({
host, options = {
agent: false,
method: "HEAD",
port: 443,
rejectUnauthorized: true,
},
}) => new Promise((resolve, reject) => {
if (!checkPort(options.port)) {
reject(Error("Invalid port"));
}
try {
const req = https.request(Object.assign({ host }, options), (res) => {
/* eslint-disable */
const { valid_from, valid_to } = res.connection.getPeerCertificate();
const validFrom = new Date(valid_from);
const validTo = new Date(valid_to);
/* eslint-enable */
resolve({
daysRemaining: getDaysRemaining(validFrom, validTo),
valid: res.socket
.authorized || false,
validFrom: validFrom.toISOString(),
validTo: validTo.toISOString(),
});
});
req.on("error", reject);
req.end();
} catch (e) {
reject(e);
}
});
export default {
sslChecker,
}; |
@dyaa Same issue as @gabrieldissotti. Below is my code (Node.js)
|
Hi guys, I have solved. First, if you want check ssl of many domains, you need use a NodeJs API, because clients can be blocked by CORS. Use this code with Node v10.x install axios with "npm i axios". create this file test.js
run with node test.js |
@gabrieldissotti This is great. Thanks. |
Issue itself is described in nodejs/node#3940, solution can be just adding an option agent with maxCachedSessions = 0: |
Big thanks to @ZitRos, This should be fixed now in version |
I found where is the problem.
There is a function:


I use this function like this:
If you don't set port 443 - everything is OK. Setting a port to 443 give us extended information about ssl errors (e.g. "Host: is not in the cert's altnames:") But if you set port 443 function works correctly only one time, next time when I call this function it leads to the crash.
The text was updated successfully, but these errors were encountered: