Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Phantomjs Processes Won't Stop #32

Open
lahdekorpi opened this issue Apr 8, 2013 · 8 comments
Open

Phantomjs Processes Won't Stop #32

lahdekorpi opened this issue Apr 8, 2013 · 8 comments

Comments

@lahdekorpi
Copy link
Contributor

My test case:

  • Run screenshot-as-a-service
  • Do 5 queries every 2 seconds
  • Wait for screenshot-as-a-service to crash

And the result is oprhaned phantomjs processes consuming memory:
Kuvankaappaus 2013-4-8 kello 16 21 34

Crash:

Sending image in response
[uncaughtException] { [Error: ENOENT, no such file or directory '/tmp/screenshot_a0759a220b50b287388af42c0149a3fe.png']
  errno: 34,
  code: 'ENOENT',
  path: '/tmp/screenshot_a0759a220b50b287388af42c0149a3fe.png',
  syscall: 'unlink' }
Stopping Phantomjs internal server

fs.js:760
  return binding.unlink(pathModule._makeLong(path));
                 ^
Error: ENOENT, no such file or directory '/tmp/screenshot_b49924b800f523f831a2c84f4ebcd53b.png'
    at Object.fs.unlinkSync (fs.js:760:18)
    at FileCleanerService.removeFile (/opt/screenshot-service/screenshot-as-a-service/lib/fileCleanerService.js:41:6)
    at FileCleanerService.removeAllFiles (/opt/screenshot-service/screenshot-as-a-service/lib/fileCleanerService.js:46:10)
    at process.<anonymous> (/opt/screenshot-service/screenshot-as-a-service/lib/fileCleanerService.js:21:10)
    at process.EventEmitter.emit (events.js:117:20)
    at process.exit (node.js:707:17)
    at process.app.configure.app.use.express.errorHandler.dumpExceptions (/opt/screenshot-service/screenshot-as-a-service/app.js:11:11)
@lahdekorpi
Copy link
Contributor Author

Maybe this bug should be cut into two;

  • Orphan phantomjs processes when service dies
  • Crashing if file isn't there anymore

I'm guessing some request already had the same url at the same time, so one of them removed it before the other.
So just wrapping the unlink function into try-catch should work?

lahdekorpi added a commit to lahdekorpi/screenshot-as-a-service that referenced this issue Apr 8, 2013
Catch error if trying to unlink a file that has been already removed by either a prior simultaneous request or some other application.
@curana
Copy link

curana commented Apr 24, 2013

This commit fixes the crash but the response remains empty. I think the caching mechanism needs some improvement.

Though I could not reproduce the big amount of phantomjs processes.

@lahdekorpi
Copy link
Contributor Author

Any ideas how to improve?

As for the processes, I got them with tens of thousands of requests in a couple of minutes...

@curana
Copy link

curana commented Apr 24, 2013

What version of phantomJS are you running?

  • Sorry, I didn't see 1.9 in the screenshot. I did not run it on Linux, I used my Mac. You have this problem with pure PhantomJS as well?

About the crash: The filename is based on a md5 hash of the options. If you switch on caching the time to elapse until you have this error should increase. If you do not use caching at all you can just add e.g. the timestamp to the filename creation.

For me the main problem seems to be that this script tries to read the screenshot, fails but does not have a fallback. I dont know if the following process would improve the situation:

  • Read the cache
  • File not found
  • Take screenshot and try again

I did not completely think about a "final solution". Maybe there are other drawbacks to handle in this case.

@lahdekorpi
Copy link
Contributor Author

# phantomjs -v
1.9.0
# node -v
v0.10.3

Yeah, I might just change the naming and see how it goes, thanks, but that doesn't solve problems that might be caused by disk errors, etc.
It's common to use NFS in this kind of situations and I'm assuming a short network hiccup would crash the whole service.

@curana
Copy link

curana commented Apr 24, 2013

If you apply the patch the service will not crash but return an empty response. I dont know if you could live with that.

You could implement a fallback if the file is not found to retry taking a screenshot, maybe with exclusive naming so nobody can delete this one special file which was created for this one request.

If I find a great solution I will let yo know.

fzaninotto added a commit that referenced this issue Apr 24, 2013
Don't crash if image doesn't exist. Related to #32
@HaNdTriX
Copy link

HaNdTriX commented Jun 7, 2013

I am having a similar Issue.

The service works for about 3000 Screenshots. But when it tries to restart itself. The this.rasterizer.kill(); does not work properly.

It fails to stop the server somehow.

Phantomjs process is sleeping. Restarting.
Stopping Phantomjs internal server
Phantomjs internal server listening on port 3001
phantomjs failed; restarting

This will go on unit I have up to 40 phantomjs servers running.

I used the latest version of screenshot-as-a-service and:

node --version
v0.11.3-pre

phantomjs --version
1.9.0

Does anyone know a Solution?

@ebuildy
Copy link

ebuildy commented Jul 18, 2014

I have same issue, phantomjs process are staying as phantom process ^^

Maybe a kind of cron task or with supervisord to kill these process ?

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

No branches or pull requests

4 participants