2
Fatal Windows exception, code 0xc0000005.
PhantomJS has crashed. Please read the bug reporting guide at 
<http://phantomjs.org/bug-reporting.html> and file a bug report.

This error pops up randomly when I am recursively opening a new page using casperJS. It's not all that random, it shows up after a couple of iterations (maybe around 50).

I don't think it's a memory leak, because I am monitoring the memory usage while running the script, and have closed all the heavy memory applications.

I've seen people reporting this issue on github, but I don't think it has a fix yet.

Is there a way I can let my machine to rerun Casper script after it detects a crash? (i.e. auto run $casperjs run.js after it detects the crash)

I was thinking to use shell script to do this, but not sure exactly how to detect the crash.

Of course, any ideas on fixing this crash would be good too.

Not sure if this helps, but I am putting my Casper code here too:

var runCasper = function(){

    casper.start('https://www.example.com', function() {
        // Do something
    });

    casper.then(function() {
        // Do something
        runCasper();
    });

    casper.run();
}
Terry Chen
  • 123
  • 4
  • 15

1 Answers1

0

One thing you can try is keep checking if the casper/phantom process is running. you can do this by writing a status file at the start and end of each run. Check out https://stackoverflow.com/a/15283576/2231632 for using filesystem within casper. Code snippted from that answer:

var fs = require('fs');
var utils = require('utils');
var data = fs.read('testdata.dat');
utils.dump(data);

And then add a shell script that frequently reads this file and if a particular process is in 'running' phase for over 10 minutes or so, you can re-run casper from the shell script.

Ideally, every recursion should have a exit condition and you can't keep on recursing forever. What is it that you want to achieve by recursively opening the same page again and again?

Community
  • 1
  • 1
Praba
  • 1,373
  • 10
  • 30
  • I am trying to scrap data from different sources. Thanks for your reply, I think it will work. Will give it a try. – Terry Chen Feb 27 '16 at 04:04
  • The reason why I close and open same page is that I want to make sure every session is new and cookies are cleared. Do you have any suggestions? – Terry Chen Feb 27 '16 at 04:06
  • Can't this be done in an infinite loop, either inside the Casper script or in a shell script outside which starts a new Casper process for each loop? – Praba Feb 27 '16 at 04:15