Tanza3D/reddark

reddark displaying privated subreddit as public

username-is-required opened this issue · 9 comments

r/askaustin, which going by this comment has been private for at least 30 minutes, is still being displayed as public.

IMG_9292

the website is loading faster than it’s ever been so i can’t imagine it’s a problem with memory/computing power right now.

in fact, the page is almost too fast… it’s making me feel like somehow the script must have found a condition to stop running the updateStatus() function at all [disclaimer, this is pure speculation on my part]

DISCLAIMER: i don’t know how accurate any of what i’ve said below is, i don’t have a pc to hand so it’s just speculation based on skimming the code and the relevant docs

i’ve been looking through main.js trying to find a condition where the script would no longer call updateStatus(). i’ve got no idea if this is what’s causing this issue or not, but it occurs to me that - when the script calls request.httpsGet, it doesn’t seem to include any handling for if the Promise is rejected. it includes a call to .then with one argument (the onFulfilled argument), but going from my very quick skim reading of MDN the method passed as onFulfilled wouldn’t be called in the event of a rejected Promise.

reddark/main.js

Line 101 in 6c29c87

request.httpsGet("/" + subreddits[section][subreddit].name + ".json").then(function (data) {

looking in requests.js, there seem to be two cases in which the Promise would be rejected.

reddark/requests.js

Lines 30 to 36 in 6c29c87

request.on('error', (err) => {
reject(err)
})
request.on('timeout', () => {
request.destroy()
reject(new Error('timed out'))
})

could this be what’s happening here? (i imagine you’ll have a better idea than me as to what’s causing it tbh as you’ll have access to the logs)

EDIT: actually i’m no longer convinced that this error is due to a rejected promise, as from what i’ve seen an uncaught rejected promise would cause the script itself to crash. hmm.

i just had an idea for a possible alternative update mechanism that might simplify things a bit (i could be wrong though)

what if, instead of having code inside updateStatus() that calls itself again when the data for (almost) all subreddits have been fetched, updateStatus() was simply a method that fetched & updated subreddit data, and was repeatedly called by use of setInterval.

i can’t figure out if this would make things better or worse so i’m gonna try and make a pr that proof-of-concepts this idea to be able to be tested (please don’t feel obligated to merge it though!)

i've been looking at the logs for a while, and it does seem like it's stopped updating. i'll try searching through the logs to see when and if it errored but it's filled with this so it'll take a bit
image

image
seems like the last call was handled here

pushed a fix for this hopefully

riiight okay, so assuming reddit sent a response that didn’t start with "<" but that still wasn’t json. i’ll update my POC PR to include some json error handling (again feel free to ignore the pr if you don’t think it’s best to merge it)

i think it's kind of best to leave it as is just because i know that works and would prefer not to go through another 2 days of random issues and oversights popping up again lol, hope you don't mind

no that’s completely fine dw. one thing i would say is that you might want to add a .catch to the end of the https request to avoid any problems being caused if requests.js rejects a promise for whatever reason (#19 is limited to this but has merge conflicts atm [edit: resolved])

i’ll close #20 but feel free to copy any of the modified code from my fork in the future if it would be helpful