저는 node, postgresql 및 전체 웹 개발 비즈니스에 익숙하지 않습니다. 나는 현재 postgres 데이터베이스에 연결하고 웹보기에서 테이블의 내용을 표시하는 간단한 응용 프로그램을 작성 중입니다. 응용 프로그램은 OpenShift에서 호스팅됩니다.node.js 및 pg에서 Postgresql 연결 시간이 초과되었습니다.
내 주요 항목이 server.js
에 있습니다
var pg = require('pg');
pg.connect(connection_string, function(err, client) {
// handle error
// save client: app.client = client;
});
이제 GET /
요청을 처리하기 위해 :
function handle_request(req, res){
app.client.query('...', function(err, result){
if (err) throw err; // Will handle error later, crash for now
res.render(...); // Render the web view with the result
});
}
내 응용 프로그램이 작동하는 것 같다 : 테이블, 정확하게 웹보기에서 렌더링되고 여러 연결 (다른 장치의 다른 웹 클라이언트)에서 작동합니다. 그러나 몇 분 동안 요청이 없다면 후속 요청으로 시간 제한 정보가있는 응용 프로그램이 중단됩니다.
/home/hai/myapp/server.js:98
if (err) throw err;
^
Error: This socket is closed.
at Socket._write (net.js:474:19)
at Socket.write (net.js:466:15)
at [object Object].query (/home/hai/myapp/node_modules/pg/lib/connection.js:109:15)
at [object Object].submit (/home/hai/myapp/node_modules/pg/lib/query.js:99:16)
at [object Object]._pulseQueryQueue (/home/hai/myapp/node_modules/pg/lib/client.js:166:24)
at [object Object].query (/home/hai/myapp/node_modules/pg/lib/client.js:193:8)
at /home/hai/myapp/server.js:97:17
at callbacks (/home/hai/myapp/node_modules/express/lib/router/index.js:160:37)
at param (/home/hai/myapp/node_modules/express/lib/router/index.js:134:11)
at pass (/home/hai/myapp/node_modules/express/lib/router/index.js:141:5)
에서 연결을 유지하는 방법이있다 (더 나은) 시간 초과 : 여기 스택 정보는? 또는 요청시 다시 연결하는 것이 가장 좋습니까? 나는 처음에 데이터베이스에 연결하지 않고 GET /
요청에 따라 앱을 재 설계하려고 시도했다. 이 솔루션은 첫 번째 요청에 대해서만 작동하고 두 번째 요청에는 충돌합니다. 모든 통찰력이 인정됩니다.
나는 그것들을 시험해 보았지만 어떤 차이도없는 것처럼 보인다. –
시도 할 수있는 다른 방법을 추가했습니다. – sheldonk
예, 연결 당 새 클라이언트 만들기가 작동합니다. 고맙습니다. –