airportyh/testem — pull request #294 by piuccio (2013-10-03 05:10:51+00:00)
Title: Handle connection reset error - ECONNRESET

This is going to be hard to explain...

I get a weird error when I try to run multiple testem in sequence only on Internet Explorer.
The error happens randomly and is rather generic `Fatal error: Can't set headers after they are sent.`

Background: I use [testem-multi](https://github.com/sideroad/testem-multi) to run multiple instances of testem in sequence. What it does is scanning my test folder and generate a `testem.json` file for each `index.html`, then it requires testem as a module and launches it in continous integration.
This was working perfectly fine in node 0.8 but sometimes it goes in error when running tests in Internet Explorer on node 0.10

Using longjhon I get a more useful error description
````
Error: read ECONNRESET
at errnoException (net.js:901:11)
at onread (net.js:556:19)
---------------------------------------------
at Readable.on (_stream_readable.js:689:33)
at res.sendfile (c:\myproject\node_modules\grunt-testem\node_modules\testem-multi\node_modules\testem\node_modules\express\lib\response.js:299:14)
at c:\myproject\node_modules\grunt-testem\node_modules\testem-multi\node_modules\testem\lib\server.js:266:15
at Object.oncomplete (fs.js:107:15)
````

I tracked done the issue and the error is raised when the browser is killed at the end of tests while it's still trying to download some resources.
In my environment this happens usually for some images or css files.

Why is this happening only on Internet Explorer? Probably because it's the only browser than when killed is sending a connection reset.
Why only on node 0.10? Probably [because of this](http://stackoverflow.com/questions/17245881/node-js-econnreset)

The fix for my use case is to add a callback on `sendFile`, this method is used to manually handle errors. In case of 'ECONNRESET' I simply ignore it.

Sorry but I can't provide an example where to reproduce the error nor a test case :cry: