fzaninotto / screenshot-as-a-service

Website screenshot service powered by node.js and phantomjs
1.1k stars 242 forks source link

Error: ENOENT, no such file or directory '/tmp/screenshot_85be4ad4e95551dd3481a21275ffbe8c.png' #54

Open vbauer opened 10 years ago

vbauer commented 10 years ago

It looks like we have a problem with file cache:

Sending image in response
Error: ENOENT, stat '/tmp/screenshot_85be4ad4e95551dd3481a21275ffbe8c.png'
{ [Error: ENOENT, no such file or directory '/tmp/screenshot_85be4ad4e95551dd3481a21275ffbe8c.png']
  errno: 34,
  code: 'ENOENT',
  path: '/tmp/screenshot_85be4ad4e95551dd3481a21275ffbe8c.png',
  syscall: 'unlink' }
Request for http://https://www.google.ru/url?sa=t,https://sites.google.com/?hl=ru - Rasterizing it
thomastraum commented 10 years ago

I am having the exact same problem, any pointers?

vbauer commented 10 years ago

Nope, I'm still waiting any news about it from author..

gcrumb commented 10 years ago

Got bitten by the same problem. Here's what I've found:

The problem originates in the phantomjs renderer, I think. If you manually call the render service with an URL that results in this error, you'll see:

curl -H "url: https://bogus.url" -H "filename: file.png" http://localhost:3001/ Error: Url returned status fail

But in spite of sending a failure message, the server doesn't return an error status (e.g. 500), so route/index.js doesn't trap this, and goes ahead and adds the filename to the collection. But when it tries to send the non-existent file, you see the above exception.

Here's a patch that will at least properly trap the error:

diff --git a/routes/index.js b/routes/index.js
index 4cc6d59..c992dd2 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -11,7 +11,7 @@ module.exports = function(app, useCors) {
   // routes
   app.get('/', function(req, res, next) {
     if (!req.param('url', false)) {
-      return res.redirect('/usage.html');
+      return res.redirect('usage.html');
     }

     var url = utils.url(req.param('url'));
@@ -75,7 +75,11 @@ module.exports = function(app, useCors) {
   }

   var callRasterizer = function(rasterizerOptions, callback) {
     request.get(rasterizerOptions, function(error, response, body) {
+                       if (body.match(/Error:/)){
+                               return callback(new Error(body));
+                       }
       if (error || response.statusCode != 200) {
         console.log('Error while requesting the rasterizer: %s', error.message);
         rasterizerService.restartService();
@@ -107,10 +111,14 @@ module.exports = function(app, useCors) {
       res.setHeader("Access-Control-Allow-Origin", "*");
       res.setHeader("Access-Control-Expose-Headers", "Content-Type");
     }
+               if (!fs.existsSync(imagePath)){
+                               console.log("File does not exist! ", imagePath);
+                               return;
+               }
     res.sendfile(imagePath, function(err) {
       fileCleanerService.addFile(imagePath);
       callback(err);
     });
   }
 

The proper thing to do, of course is to get the rendering service to return an appropriate HTTP response status.

slorber commented 9 years ago

I have the same problem here.

It seems it happens mostly for bad URLs, but also for HTTPS protocol (not always however).

For exemple I have some cases where only the HTTPS version fails:

OK: http://localhost:3000/?url=http://en.wikipedia.org/wiki/User_agent
KO: http://localhost:3000/?url=https://en.wikipedia.org/wiki/User_agent

OK: http://localhost:3000/?url=http://leverich.github.io/swiftislikescala/
KO: http://localhost:3000/?url=https://leverich.github.io/swiftislikescala/

Yes according to what I see, PhantomJS returns a status code 200 with body Error: Url returned status fail\n

Any solution?

vbauer commented 9 years ago

To solve this problem, I built my own lunar lander, with blackjack and hookers: https://github.com/vbauer/manet

slorber commented 9 years ago

@vbauer thanks, glad to know. I may switch to your service if I can't solve my problems with actual server.

For into those having problems with HTTPS I think this is because of this PhantomJS problem: http://stackoverflow.com/questions/12021578/phantomjs-failing-to-open-https-site

candu commented 7 years ago

This was fixed for me by upgrading to phantomjs 2.1.1 - haven't investigated enough to know why. (I was previously on phantomjs 1.9.8; ran both times under node v6.7.0.)