Skip to content

ECONNRESET with unpooled connection / close #1344

@aahoughton

Description

@aahoughton

We're in the process of bringing up our (normally AWS-based) stack on azure with a hosted PG instance. Azure apparently requires SSL (which may or may not be important, but it's in the stack trace, so..)

We're running into issues with unpooled connections (used to verify DB availability) in our periodic DB status tests. node version is 6.9.0; node-postgres version is 6.4. Code looks like this (w/o longjohn):

require('longjohn');
const pg = require('pg');

const DSN = 'postgres://uid:pwd@azure_db:5432/imp?ssl=true';

function status(cb) {
    var start = Date.now();
    var client = new pg.Client(DSN);
    client.connect(function(err) {
        if (err) {
            return cb(err);
        }

        client.query("select 1 as pong", function(err, results) {
            client.end();

            if (err) {
                return cb(err);
            }

            if (!results.rows || results.rows.length !== 1 || results.rows[0].pong !== 1) {
                return cb(new Error("expected pong of 1"));
            }

            return cb(null, Date.now() - start);
        });
    });
}

setInterval(function() {
    console.log(new Date().toISOString());
    status(function(err, latency) {
        if (err) {
            console.error(err);
        }
    })
}, 5000);

.. errors (after 5s) with this:

Error: read ECONNRESET
    at exports._errnoException (util.js:1022:11)
    at TLSWrap.onread (net.js:569:26)
---------------------------------------------
    at Client.connect (/home/andrew/tmp/node_modules/pg/lib/client.js:184:7)
    at status (/home/andrew/tmp/test-unpooled-pg.js:9:12)
    at Timeout.<anonymous> (/home/andrew/tmp/test-unpooled-pg.js:32:5)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

.. seems like it may be related to #314 but unclear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions