From 8b3c256a5c06c0664f5411ff3c45c0c66f82fffe Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 13 Oct 2022 17:00:21 -0700 Subject: [PATCH] Time out manifest requests after 2sec We do a thing where we sometimes proactively update an appearance layer's manifest from images.neopets.com when it's been a while since the last time, _during_ user requests. But when images.neopets.com is being slow, this makes our API requests about appearances super slow, too! In this change, we add a 2-second timeout to those requests. That should be plenty for when images.neopets.com is in a good mood, but also give up fast enough for the site to not feel miserable lol :p (especially when the use "Use DTI's image archive" option is on!) --- src/server/types/AppearanceLayer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/types/AppearanceLayer.js b/src/server/types/AppearanceLayer.js index 2750a8c..2c94a29 100644 --- a/src/server/types/AppearanceLayer.js +++ b/src/server/types/AppearanceLayer.js @@ -585,7 +585,12 @@ async function loadAndCacheAssetDataFromManifest(db, layer) { async function loadAndCacheAssetManifest(db, layer) { let manifest; try { - manifest = await loadAssetManifest(layer.url); + manifest = await Promise.race([ + loadAssetManifest(layer.url), + new Promise((_, reject) => + setTimeout(() => reject(new Error(`manifest request timed out`)), 2000) + ), + ]); } catch (e) { console.error( new Error("Error loading asset manifest, caused by the error below")