buddycloud/buddycloud-server — Issue #40: server crash on postgres connection
Author: highfellow
Created: 2012-02-01 20:12:00+00:00
State: open

My server has just crashed with this error:

```
net.js:451
if (!this._handle) throw new Error('This socket is closed.');
^
Error: This socket is closed.
at Socket._write (net.js:451:28)
at Socket.write (net.js:444:15)
at [object Object].query (/home/highfellow/lib/node_modules/buddycloud-server/node_modules/pg/lib/connection.js:108:15)
at [object Object].submit (/home/highfellow/lib/node_modules/buddycloud-server/node_modules/pg/lib/query.js:99:16)
at [object Object]._pulseQueryQueue (/home/highfellow/lib/node_modules/buddycloud-server/node_modules/pg/lib/client.js:166:24)
at [object Object]. (/home/highfellow/lib/node_modules/buddycloud-server/node_modules/pg/lib/client.js:193:8)
at [object Object].query (/home/highfellow/lib/node_modules/buddycloud-server/lib/local/model_postgres.js:24:23)
at new Transaction (/home/highfellow/lib/node_modules/buddycloud-server/lib/local/model_postgres.js:170:10)
at /home/highfellow/lib/node_modules/buddycloud-server/lib/local/model_postgres.js:80:14
at /home/highfellow/lib/node_modules/buddycloud-server/lib/local/model_postgres.js:61:14
at /home/highfellow/lib/node_modules/buddycloud-server/lib/local/model_postgres.js:79:12
```

Which corresponds to this line in model_postgres.js:

```
exports.transaction = function(cb) {
return withNextDb(function(db) {
return new Transaction(db, cb);
});
};
```

and (I think) this line in model_postgres.coffee:

```
exports.transaction = (cb) ->
withNextDb (db) ->
new Transaction(db, cb)
```

It looks to me as if it's failing rather than waiting and retrying if the local postgres server is down for a while, but I may be wrong, and I'm not sure how best to code a patch.

Hope this is useful.