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


i've been playing around socket.io , seems have been working nicely. lately though, installed postgresql insert rows database everytime event happens (and event happens 2 or 3 times per second!)... here's snippet:

pg.connect(constring, function(err, dbclient) {   io.sockets.on("connection", function(client) {     client.on("clientsendingplayerdata", function(playerdata) {       dbclient.query("insert actions values (1)", function() {         console.log("inserted row");       });     });   }); }); 

we error:

net.js:391     throw new error('socket not writable');           ^ error: socket not writable     @ socket._writeout (net.js:391:11)     @ socket.write (net.js:377:17)     @ [object object].query (/homes/jjl310/node_modules/pg/lib/connection.js:109:15)     @ [object object].submit (/homes/jjl310/node_modules/pg/lib/query.js:99:16)     @ [object object]._pulsequeryqueue (/homes/jjl310/node_modules/pg/lib/client.js:166:24)     @ [object object].query (/homes/jjl310/node_modules/pg/lib/client.js:193:8)     @ socket.<anonymous> (/homes/jjl310/tradersgame/server.js:182:16)     @ socket.$emit (events.js:64:17)     @ socketnamespace.handlepacket (/homes/jjl310/node_modules/socket.io/lib/namespace.js:335:22)     @ manager.onclientmessage (/homes/jjl310/node_modules/socket.io/lib/manager.js:469:38) 

any ideas what's causing problem , how fixed?

i'm using following library postrgresql https://github.com/brianc/node-postgres

pg.connect() gets connection pool, dbclient active connection. long running connections can timeout, error or dropped inactivity. want move pg.connect() in clientsendingplayerdata callback. way db connetion gets pull pool when needed , returned pool when finished.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -