Skip to content

Commit

Permalink
Revert "When connection fail, emit the error. (brianc#28)"
Browse files Browse the repository at this point in the history
This reverts commit 6a7edab.

The callback passed to `Pool.prototype.connect` should be responsible for handling connection errors. The `error` event is documented to be:

> Emitted whenever an idle client in the pool encounters an error.

This isn’t the case of an idle client in the pool; it never makes it into the pool.

It also breaks tests on pg’s master because of nonspecific dependencies.
  • Loading branch information
charmander committed Oct 28, 2016
1 parent fbdfc15 commit c868226
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Pool.prototype._create = function (cb) {
if (err) {
this.log('client connection error:', err)
cb(err)
this.emit('error', err)
} else {
this.log('client connected')
this.emit('connect', client)
Expand Down
26 changes: 2 additions & 24 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('events', function () {
})
})

it('emits "error" with a failed connection', function (done) {
it('emits "connect" only with a successful connection', function (done) {
var pool = new Pool({
// This client will always fail to connect
Client: mockClient({
Expand All @@ -34,29 +34,7 @@ describe('events', function () {
pool.on('connect', function () {
throw new Error('should never get here')
})
pool.on('error', function (err) {
if (err) done()
else done(new Error('expected failure'))
})
pool.connect()
})

it('callback err with a failed connection', function (done) {
var pool = new Pool({
// This client will always fail to connect
Client: mockClient({
connect: function (cb) {
process.nextTick(function () { cb(new Error('bad news')) })
}
})
})
pool.on('connect', function () {
throw new Error('should never get here')
})
pool.on('error', function (err) {
if (!err) done(new Error('expected failure'))
})
pool.connect(function (err) {
pool._create(function (err) {
if (err) done()
else done(new Error('expected failure'))
})
Expand Down

0 comments on commit c868226

Please sign in to comment.