최근에 제네릭 풀 패키지를 버전 3으로 업그레이드했습니다.이 패키지는 약속을 사용하기 때문에 충분히 이해하지 못합니다. 예상치 못한 작동 차이에도 불구하고 제대로 작동하도록했습니다.Node.js 연결 풀에서 오류가 발생하면 무한 루프가 발생합니다.
내가 가진 문제는 오류 조건을 테스트하기 시작할 때입니다. 나는 의도적으로 암호를 잘못 설정했으며, 테스트 할 때 무언가 "연결에 실패했습니다"오류가 발생합니다 - 오류가 있음에도 불구하고 뭔가가 작성 기능을 트리거하고 있음을 나타냅니다. 내가 수영장을 잘못 구성했다고 가정하거나 부적절하게 습득하고 있습니다.
일반 수영장 공장 :
const poolFactory = {
create: function() {
return new Promise(function(resolve, reject) {
var client = mysql.createConnection({
host: config.host,
user: config.user,
password: config.pass,
});
client.connect(function(err) {
if (err != null) {
log.write('ERROR', "Connection Error: MySQL: " + err.message);
reject(err);
} else {
log.write('INFO', "MySQL Connection created.");
resolve(client);
}
});
})
},
destroy: function(client) {
return new Promise(function(resolve) {
client.end(function(err) {
if (err != null) {
log.write('ERROR', "DB Error: MySQL: " + err.message);
} else {
log.write('INFO', "Database connection closed.");
resolve();
}
});
})
}
}
const cp = genericPool.createPool(poolFactory);
연결 오류 트리거
테스트 쿼리
Connection Error: MySQL: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'localhost' (using password: YES)
내가 : 백만 라인
이cp.acquire().then(
function(client) {
client.query('USE ' + config.db, function(err, results, fields) {
if (err != null) {
log.write('ERROR', "DB test error: MySQL: " + err.message);
} else {
log.write('INFO', "MySQL connection tested successfully.");
cp.release(client)
}
});
}).catch(function(err) {
cp.release(client);
log.write('ERROR', "Pool Error: " + err.message);
});
내 오류 로그가 가득를 오류 조건을 테스트 중이므로 단일 오류가 예상됩니다. 무한 루프를 얻으려면 무엇을 잘못하고 있습니까? 나는 그 거부 (잘못)가 더 이상의 질문에 대답하지 않을 상태에서 약속을 지어야한다고 생각 했단 말인가?
누구나 올바른 방향으로 나를 가리킬 수 있습니까?
언제나처럼 - 고맙습니다.
EDIT : 다음은 처음으로 문제를 직접 보면서 문제를 설명하는 전체 스크립트입니다! 콘솔에 "ERROR MySQL 연결 오류 : ER_ACCESS_DENIED_ERROR : 사용자 'devUser'@ 'localhost'(비밀번호 사용 : 예)에 대한 액세스가 거부되었습니다."라는 메시지가 콘솔에 표시됩니다. 다시 한번 감사드립니다. GitHub의 문제에 대한 내 원래의 응답에서
// Test App to show logging issue
var pool = require('generic-pool'),
mysql = require('mysql')
var config = {
port: 8880,
host: 'localhost',
user: 'devUser',
pass: 'wrong-pass',
db: 'node-app-db'
}
const poolConfig = {
max: 3
};
const poolFactory = {
create: function() {
return new Promise(function(resolve, reject) {
var client = mysql.createConnection({
host: config.host,
user: config.user,
password: config.pass,
});
client.connect(function(err) {
if (err != null) {
console.log('ERROR', "MySQL Connection Error: " + err.message);
reject(err);
} else {
console.log('USAGE', "MySQL Connection created. " + cp.size + " of " + config.poolSize + " connections to DB in use.");
resolve(client);
}
});
})
},
destroy: function(client) {
return new Promise(function(resolve) {
client.end(function(err) {
if (err != null) {
console.log('ERROR', "DB Error: MySQL: " + err.message);
} else {
console.log('USAGE', "Database connection closed. Pool contains ' + cp.size + ' more connections.");
resolve();
}
});
})
}
}
const cp = pool.createPool(poolFactory, poolConfig);
cp.acquire().then(
function(client) {
client.query('USE ' + config.db, function(err, results, fields) {
if (err != null) {
console.log('ERROR', "DB test error: MySQL: " + err.message);
} else {
console.log('READY', "MySQL connection tested successfully. DataServer ready for connections.");
cp.release(client)
}
});
}).catch(function(err) {
cp.release(client);
console.log('ERROR', "Pool Error: " + err.message);
});
약속이'poolFactory에서 반환되었습니다. 그 경우에는'create'가 거부 될 것입니다 ...'cp.acquire()'에서 반환 된 약속과 관련이있는 것을 볼 수 없습니다 ... 응답을 보유 할 수있는 코드가 누락 된 것 같습니다 –
코드가 누락되었습니다. 코드에 내가 너를 보여주지 않았 니? 또는 응용 프로그램에 넣지 않은 코드? – whiteatom
흠 .. 아마도이 패키지에 대해 알려진 이슈로 보입니다. – whiteatom