mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-11-23 14:46:44 +09:00
enhance(backend): check_connect.js で全RedisとDBへの接続を確認するように (#14853)
* fix race conditions in check_connect.js (cherry picked from commit 524ddb96770690455b82522104a543c5b0b1f3b3) * fix * Update Changelog --------- Co-authored-by: Hazelnoot <acomputerdog@gmail.com>
This commit is contained in:
parent
8eb7749e44
commit
f30d19051f
@ -24,6 +24,9 @@
|
||||
- Fix: リンク切れを修正
|
||||
|
||||
### Server
|
||||
- Enhance: 起動前の疎通チェックで、DBとメイン以外のRedisの疎通確認も行うように
|
||||
(Based on https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/588)
|
||||
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/715)
|
||||
- Fix: Nested proxy requestsを検出した際にブロックするように
|
||||
[ghsa-gq5q-c77c-v236](https://github.com/misskey-dev/misskey/security/advisories/ghsa-gq5q-c77c-v236)
|
||||
- Fix: 招待コードの発行可能な残り数算出に使用すべきロールポリシーの値が違う問題を修正
|
||||
|
@ -5,11 +5,52 @@
|
||||
|
||||
import Redis from 'ioredis';
|
||||
import { loadConfig } from '../built/config.js';
|
||||
import { createPostgresDataSource } from '../built/postgres.js';
|
||||
|
||||
const config = loadConfig();
|
||||
const redis = new Redis(config.redis);
|
||||
|
||||
redis.on('connect', () => redis.disconnect());
|
||||
redis.on('error', (e) => {
|
||||
throw e;
|
||||
});
|
||||
async function connectToPostgres() {
|
||||
const source = createPostgresDataSource(config);
|
||||
await source.initialize();
|
||||
await source.destroy();
|
||||
}
|
||||
|
||||
async function connectToRedis(redisOptions) {
|
||||
return await new Promise(async (resolve, reject) => {
|
||||
const redis = new Redis({
|
||||
...redisOptions,
|
||||
lazyConnect: true,
|
||||
reconnectOnError: false,
|
||||
showFriendlyErrorStack: true,
|
||||
});
|
||||
redis.on('error', e => reject(e));
|
||||
|
||||
try {
|
||||
await redis.connect();
|
||||
resolve();
|
||||
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
||||
} finally {
|
||||
redis.disconnect(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If not all of these are defined, the default one gets reused.
|
||||
// so we use a Set to only try connecting once to each **uniq** redis.
|
||||
const promises = Array
|
||||
.from(new Set([
|
||||
config.redis,
|
||||
config.redisForPubsub,
|
||||
config.redisForJobQueue,
|
||||
config.redisForTimelines,
|
||||
config.redisForReactions,
|
||||
]))
|
||||
.map(connectToRedis)
|
||||
.concat([
|
||||
connectToPostgres()
|
||||
]);
|
||||
|
||||
await Promise.allSettled(promises);
|
||||
|
Loading…
Reference in New Issue
Block a user