Node-postgres pool.connect becomes unresponsive









up vote
0
down vote

favorite












Hiii,
Recently my elastic beanstalk server have started to become unresponsive and return's 504 gateway timeout. I suspect that my pool.connect is becoming unresponsive and there are no logs reporting error while connecting to pool but it stucks at connecting. My other controllers with no database query works fine.
This goes away when I restart the server but after some time same thing happens.



I making requests this way-
1) database.js



const pg = require("pg")
// setting timestamp for the postgres.
pg.types.setTypeParser(1184, function(stringValue)

console.log(stringValue)
return new Date(Date.parse(Date.parse(stringValue + "+0000")))
)

// configuration for postres for connecting.
const pgConfig =
user: "USER",
database: "DATABASE",
password: "1234",
port: 5432

const pool = new pg.Pool(pgConfig)
module.exports = pool


2) somecontroller.js



const db = require("../database/database")
const constant = require("../utility/constant")

module.exports = function(req, res)


db.connect(function(err, client, done)

if(err)

done()
console.log(constant.error.db.CONNECT_CONSOLE, err)
return res.send(status: constant.status.ERROR, code: constant.error.db.CONNECT)


client.query("QUERY", [UID])
.then(result =>

// Processing this queries and Some other query.....
)
.catch(err =>

console.log(constant.error.db.QUERY_CONSOLE, err)
res.send(status: constant.status.ERROR, code: constant.error.db.QUERY)
)

done()
)



My every controller works in similar fashion.



Thanks,










share|improve this question























  • When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
    – robertklep
    Nov 11 at 11:42










  • @robertklep should i increase pool size??
    – Zicsus
    Nov 11 at 12:52










  • I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
    – robertklep
    Nov 11 at 12:57










  • @robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
    – Zicsus
    Nov 11 at 16:51














up vote
0
down vote

favorite












Hiii,
Recently my elastic beanstalk server have started to become unresponsive and return's 504 gateway timeout. I suspect that my pool.connect is becoming unresponsive and there are no logs reporting error while connecting to pool but it stucks at connecting. My other controllers with no database query works fine.
This goes away when I restart the server but after some time same thing happens.



I making requests this way-
1) database.js



const pg = require("pg")
// setting timestamp for the postgres.
pg.types.setTypeParser(1184, function(stringValue)

console.log(stringValue)
return new Date(Date.parse(Date.parse(stringValue + "+0000")))
)

// configuration for postres for connecting.
const pgConfig =
user: "USER",
database: "DATABASE",
password: "1234",
port: 5432

const pool = new pg.Pool(pgConfig)
module.exports = pool


2) somecontroller.js



const db = require("../database/database")
const constant = require("../utility/constant")

module.exports = function(req, res)


db.connect(function(err, client, done)

if(err)

done()
console.log(constant.error.db.CONNECT_CONSOLE, err)
return res.send(status: constant.status.ERROR, code: constant.error.db.CONNECT)


client.query("QUERY", [UID])
.then(result =>

// Processing this queries and Some other query.....
)
.catch(err =>

console.log(constant.error.db.QUERY_CONSOLE, err)
res.send(status: constant.status.ERROR, code: constant.error.db.QUERY)
)

done()
)



My every controller works in similar fashion.



Thanks,










share|improve this question























  • When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
    – robertklep
    Nov 11 at 11:42










  • @robertklep should i increase pool size??
    – Zicsus
    Nov 11 at 12:52










  • I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
    – robertklep
    Nov 11 at 12:57










  • @robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
    – Zicsus
    Nov 11 at 16:51












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hiii,
Recently my elastic beanstalk server have started to become unresponsive and return's 504 gateway timeout. I suspect that my pool.connect is becoming unresponsive and there are no logs reporting error while connecting to pool but it stucks at connecting. My other controllers with no database query works fine.
This goes away when I restart the server but after some time same thing happens.



I making requests this way-
1) database.js



const pg = require("pg")
// setting timestamp for the postgres.
pg.types.setTypeParser(1184, function(stringValue)

console.log(stringValue)
return new Date(Date.parse(Date.parse(stringValue + "+0000")))
)

// configuration for postres for connecting.
const pgConfig =
user: "USER",
database: "DATABASE",
password: "1234",
port: 5432

const pool = new pg.Pool(pgConfig)
module.exports = pool


2) somecontroller.js



const db = require("../database/database")
const constant = require("../utility/constant")

module.exports = function(req, res)


db.connect(function(err, client, done)

if(err)

done()
console.log(constant.error.db.CONNECT_CONSOLE, err)
return res.send(status: constant.status.ERROR, code: constant.error.db.CONNECT)


client.query("QUERY", [UID])
.then(result =>

// Processing this queries and Some other query.....
)
.catch(err =>

console.log(constant.error.db.QUERY_CONSOLE, err)
res.send(status: constant.status.ERROR, code: constant.error.db.QUERY)
)

done()
)



My every controller works in similar fashion.



Thanks,










share|improve this question















Hiii,
Recently my elastic beanstalk server have started to become unresponsive and return's 504 gateway timeout. I suspect that my pool.connect is becoming unresponsive and there are no logs reporting error while connecting to pool but it stucks at connecting. My other controllers with no database query works fine.
This goes away when I restart the server but after some time same thing happens.



I making requests this way-
1) database.js



const pg = require("pg")
// setting timestamp for the postgres.
pg.types.setTypeParser(1184, function(stringValue)

console.log(stringValue)
return new Date(Date.parse(Date.parse(stringValue + "+0000")))
)

// configuration for postres for connecting.
const pgConfig =
user: "USER",
database: "DATABASE",
password: "1234",
port: 5432

const pool = new pg.Pool(pgConfig)
module.exports = pool


2) somecontroller.js



const db = require("../database/database")
const constant = require("../utility/constant")

module.exports = function(req, res)


db.connect(function(err, client, done)

if(err)

done()
console.log(constant.error.db.CONNECT_CONSOLE, err)
return res.send(status: constant.status.ERROR, code: constant.error.db.CONNECT)


client.query("QUERY", [UID])
.then(result =>

// Processing this queries and Some other query.....
)
.catch(err =>

console.log(constant.error.db.QUERY_CONSOLE, err)
res.send(status: constant.status.ERROR, code: constant.error.db.QUERY)
)

done()
)



My every controller works in similar fashion.



Thanks,







javascript node.js postgresql rest freeze






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 8:11

























asked Nov 11 at 7:23









Zicsus

302212




302212











  • When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
    – robertklep
    Nov 11 at 11:42










  • @robertklep should i increase pool size??
    – Zicsus
    Nov 11 at 12:52










  • I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
    – robertklep
    Nov 11 at 12:57










  • @robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
    – Zicsus
    Nov 11 at 16:51
















  • When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
    – robertklep
    Nov 11 at 11:42










  • @robertklep should i increase pool size??
    – Zicsus
    Nov 11 at 12:52










  • I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
    – robertklep
    Nov 11 at 12:57










  • @robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
    – Zicsus
    Nov 11 at 16:51















When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
– robertklep
Nov 11 at 11:42




When database pools become unresponsive, it's typically caused by connections not being return into the pool or because queries taking a lot of time and the pool size being too small (so at some point, all connections are waiting for a query to finish and new requests are piling up).
– robertklep
Nov 11 at 11:42












@robertklep should i increase pool size??
– Zicsus
Nov 11 at 12:52




@robertklep should i increase pool size??
– Zicsus
Nov 11 at 12:52












I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
– robertklep
Nov 11 at 12:57




I'm just providing some possible reasons why the connections may be timing out. I don't run your app so can't tell specifically which reason (if any) is causing your specific problems. You need to debug your app yourself and rule out things.
– robertklep
Nov 11 at 12:57












@robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
– Zicsus
Nov 11 at 16:51




@robertklep i found the issue. It was a controller which was not releasing client properly. I still increased the pool size. Thanks for helping though.
– Zicsus
Nov 11 at 16:51

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246673%2fnode-postgres-pool-connect-becomes-unresponsive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246673%2fnode-postgres-pool-connect-becomes-unresponsive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto