gruntjs / grunt-lib-phantomjs

Grunt and PhantomJS, sitting in a tree.
http://gruntjs.com/
MIT License
93 stars 63 forks source link

Fix EBUSY error on Windows when deleting temp file #84

Closed Xeio closed 9 years ago

Xeio commented 9 years ago

I'm seeing an error sometimes when I run qunit tests with Grunt on Windows. Error message: "Fatal error: EBUSY, resource busy or locked" for the temp file used by PhantomJS.

This pull request has a fix for the issue, basically just retrying the unlink if it fails due to an EBUSY error.

sindresorhus commented 9 years ago

That's a bad solution as the file might be busy for a long time or infinity.

Better to just use https://github.com/isaacs/node-graceful-fs for fs operations.

Xeio commented 9 years ago

I tried using graceful-fs but now I just see EPERM errors instead of EBUSY. Not sure if I'm misusing the library or if there's some additional settings that are needed for that library to wrap the errors.

I could clean up the file a little more deterministically, by doing it after the PhantomJS process is terminated (since that's what's keeping the file open), but I'm not sure how to do this without doing at least one wait period.

Maybe just only retry once? I never saw it take more than one wait period in practice but that would be machine specific.