Timeout not respected
wouterlemcke opened this issue · 7 comments
We noticed the configured timeout is not respected.
await getLinkPreview(url, {
imagesPropertyType: 'og',
headers: {
'user-agent': 'googlebot'
},
timeout: 1000,
}))
When trying to generate a link preview for for example https://video013.kerkomroep.nl/pages/afspelen.php?mp=11115&file=2022-07-03-08-41-15.mp4 it never times out.
The weird thing is that when I set timeout to 10 it works, but as soon as I put it on 100 or above it just freezes.
I can see the tests fail on the github runner, but on my local machine they work fine, so it probably has something to do with the node version. ping @wouterlemcke, can you provide more info where are you running this? node? which version? etc.
Sorry for the slow response, I was on holiday 😄
We are running Node 14.19.3 on AWS EC2s, but also locally on my Macbook (running Node 14.19.0) I can reproduce it
Haha, that's annoying. I can share my temp. solution:
const linkPreview = (await Promise.race([
getLinkPreview(url, {
imagesPropertyType: 'og',
headers,
timeout,
followRedirects: 'manual',
handleRedirects: (baseURL: string, forwardedURL: string) => {
return LinkPreviewRedirect.isWhiteListed(baseURL, forwardedURL)
},
resolveDNSHost: async (url: string) => {
const hostname = new URL(url).hostname
const result = await dns.promises.lookup(hostname)
return result.address
},
}),
new Promise((resolve, reject) => {
setTimeout(() => {
reject(new GeneratingLinkPreviewFailedException('Timeout'))
}, timeout)
}),
]))
Going to close this, node 14 has already reached eol on active support (despite security patches). And there is the existing workaround you posted.