title: node.js with PostgreSQL and socket.io Error: Socket is not writable
body: <p>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:</p>
  
  <pre><code>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");
        });
      });
    });
  });
  </code></pre>
  
  <p>We get the error:</p>
  
  <pre><code>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.&lt;anonymous&gt; (/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)
  </code></pre>
  
  <p>Any ideas as to what's causing the problem and how it could be fixed?</p>
  
  <p>I'm using the following library for postrgreSQL
  <a href="https://github.com/brianc/node-postgres" rel="nofollow">https://github.com/brianc/node-postgres</a></p>