Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The loadImage() method can fail with Request timed out error on older hardware #2363

Open
1 task done
Cryotalis opened this issue Mar 13, 2024 · 2 comments
Open
1 task done

Comments

@Cryotalis
Copy link

Cryotalis commented Mar 13, 2024

Issue

Issue does not occur on my desktop PC, but on my weaker and older laptop (where I'm hosting my app), the loadImage() method can fail with a Request timed out error (at simple-get/index.js:75:8) when loading from an image link. I can resolve this issue myself by going into node modules and setting a 10 second timeout in either the simple-get module itself or the node-canvas module where simple-get is being called (canvas > lib > image.js), but obviously this isn't ideal because my modification can get overwritten when I update my dependencies. The loadImage() method has an options parameter, but I don't think this options parameter has anything to do with the options you can set for simple-get. If there is a way to set a timeout without locally editing simple-get or node-canvas, please enlighten me. I was able to get around this issue by rewriting my code to load the images in a slightly different way, but I'd appreciate being able to set a timeout.

Environment

  • Version of node-canvas: 2.11.2
  • Environment: node 21.4.0 on Ubuntu Server
@oliverkeen15
Copy link

@Cryotalis I am having the same issue, have you figured out a workaround?

@Cryotalis
Copy link
Author

@oliverkeen15 What I did may not work for you, but previously I was pushing loadImage() calls (loading from image links) to an array in a forEach loop and then calling Promise.All() on that array to ensure that the images were loaded. I modified it to push the image links themselves to an array, which I then mapped to loadImage() calls inside of a Promise.All() call after the forEach loop terminated like so: await Promise.all(links.map(link => loadImage(link))). I've not had any issues since. Perhaps it had something to do with the calculations and whatnot in my loop sometimes interfering with the ability of loadImage to process the image links.

This was a very confusing issue to deal with as I tested many sets of image links and there seemed to be no rhyme or reason as to why only certain sets of links would consistently fail and others would not. It did not seem to have anything to do with the number of links I was processing at once and the issue was also not being caused by specific image links as far as I could tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants