node.js with PostgreSQL and socket.io Error: Socket is not writable

I've been playing around with socket.io and it seems to have been working nicely. Lately though, I installed postgreSQL to insert rows to the database everytime an event happens (and the event happens 2 or 3 times per second!)... Here's a snippet:

pg.connect(conString, function(err, dbClient) {
  io.sockets.on("connection", function(client) {
    client.on("clientSendingPlayerData", function(playerData) {
      dbClient.query("insert into actions values (1)", function() {
        console.log("INSERTED ROW");
      });
    });
  });
});

We get the error:

net.js:391
    throw new Error('Socket is not writable');
          ^
Error: Socket is not writable
    at Socket._writeOut (net.js:391:11)
    at Socket.write (net.js:377:17)
    at [object Object].query (/homes/jjl310/node_modules/pg/lib/connection.js:109:15)
    at [object Object].submit (/homes/jjl310/node_modules/pg/lib/query.js:99:16)
    at [object Object]._pulseQueryQueue (/homes/jjl310/node_modules/pg/lib/client.js:166:24)
    at [object Object].query (/homes/jjl310/node_modules/pg/lib/client.js:193:8)
    at Socket.<anonymous> (/homes/jjl310/tradersgame/server.js:182:16)
    at Socket.$emit (events.js:64:17)
    at SocketNamespace.handlePacket (/homes/jjl310/node_modules/socket.io/lib/namespace.js:335:22)
    at Manager.onClientMessage (/homes/jjl310/node_modules/socket.io/lib/manager.js:469:38)

Any ideas as to what's causing the problem and how it could be fixed?

I'm using the following library for postrgreSQL https://github.com/brianc/node-postgres

pg.connect() gets a connection from the pool, dbClient is an active connection. Long running connections can timeout, error or be dropped for inactivity. You want to move pg.connect() in to the clientSendingPlayerData callback. That way a db connetion gets pull from the pool only when needed and is returned to the pool when finished.