simplereach/helenus — pull request #84 by calvinfo (2012-10-25 23:58:29+00:00)
Title: Adding destroy method to connection pool as well as tests

**Note**: this will only pass when run with the helenus-thrift version I've pull requested: https://github.com/simplereach/node-thrift/pull/6

I've recently been trying to handle connection errors in the case of a node going down in the middle of a write.

Unless I'm missing something, my best course of action is to:

1. listen on pool errors
2. close the current pool
3. try reconnecting

```javascript
pool.on('error', function () {
pool.close();
pool.connect([...]);
});
```

The problem here is that calling `close` on a connection tries to drain all the writes from it by [calling `end` on its internal connection](https://github.com/simplereach/helenus/blob/master/lib/connection.js#L514). See the [net connection .end()](http://nodejs.org/api/net.html#net_socket_end_data_encoding) and the [stream .end()](http://nodejs.org/api/stream.html#stream_stream_end). This causes all my queued writes to hang for a node that usually isn't coming up anytime soon. The client should be able to choose between discarding those writes for the sake of returning quickly (via `destroy`) or deciding to wait on the queued data (via `close`)

Thoughts?