jmreidy / grunt-mocha-webdriver

Grunt task to run Mocha tests against a WebDriver source - either PhantomJS or Sauce Labs
MIT License
36 stars 17 forks source link

Using child_process.spawn over execFile to avoid buffer overflow #94

Closed jamesseanwright closed 9 years ago

jamesseanwright commented 9 years ago

For the last couple of days my colleague (@DanForys) and I have been stumped with a rather unusual error, by which extending our codebase would cause PhantomJS to die; it turns out that the increase in data that Phantom pumped into stdout was causing a buffer overflow.

As explained in Hack Sparrow's post detailing the differences between child_process.spawn and exec, "child_process.exec returns the whole buffer output from the child process. By default the buffer size is set at 200k. If the child process returns anything more than that, you program will crash". child_process.spawn does not have this same restriction, which I imagine is down to how one references standard streams between the two methods. This single change resolved this issue for us.