My problem is probably straight forward, but I can't figure out what's happening behind the scenes. I'm looping through a series of domains in a database table, calling out to them, grabbing the SSL certificate and storing information about it back into the database.
For the most part, it's working - except when the loop exits any calls that haven't get completed just stop dead.
Database retrieval that begins check:
function queryRows() {
complete = false;
var query = c.query("SELECT * FROM domains LIMIT 100 OFFSET " + offset);
query.on('result', function(res) {
res.on('data', function(row) {
checkUrl(row)
}).on('end', function() {
complete = true;
});
}).on('end', function() {
console.log(complete);
offset += 100;
if(offset <= (parseInt(rows) + 400)){
queryRows();
} else {
console.log("Done, waiting");
setTimeoutPromise(600000, 'foobar').then((value) => {
console.log("restarting")
offset = 0;
getTotal();
});
}
});
}
And the code that checks the SSL:
function checkSSL(id, domain){
complete = false
var options = {
host: domain,
rejectUnauthorized: false
};
callback = function(response) {
var str = '';
try {
if(domain == "arstechnica.com"){
console.log("Found ars - savingCertificate");
}
cert = response.connection.getPeerCertificate(true);
complete = hasSSL(cert, domain, id);
// updateDomainRecord(cert, domain, id)
} catch (error){
console.log(error);
complete = true;
noSSLRecord(domain, id);
}
}
const req = https.request(options, callback);
req.on('error', (e) => {
// console.error(e);
});
}
It's worth noting that if I put a console.log before https.request, I see it in my console. However any logs within the callback fail to trigger (because the callback itself never fires).
Again, some of the time the callback does. It is only near the end of the database loop where it appears to stop working. Any advice would be appreciated!
console.log(response)
right aftercallback = function(response) {
It logs something? – Kenethreq.end()
, which is when your request actually gets sent. Your request appears to be perpetually waiting for you to write a body to it. – Jangrocomplete = hasSSL(cert, domain, id);
it's not consistent with your function definition. – Teirtza