PG似乎并没有正确closures连接

我正在编写一个使用Node.js和postgresql的应用程序。 当用户validation它击中数据库来检查用户的密码,然后应该closures连接到数据库。 但是,如果用户input了错误的密码并再次尝试进行身份validation,则在服务器控制台上出现此错误:

UNCAUGHT EXCEPTION... { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' } Error: write EPIPE 

我相信它不是第一次正确closures连接。 这是应该closures连接的脚本的一部分:

 query.on('end', function(){ client.end(); if (pass == this.dbpass){ console.log(pass); console.log(this.dbpass); return callback (200, "OK", {}, true); } else { console.log(pass); return callback(200, "OK", {}, false); } }); 

有没有另一种方法来closures我不知道的连接?