Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(backend): check_connect.js で全RedisとDBへの接続を確認するように #14853

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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: 招待コードの発行可能な残り数算出に使用すべきロールポリシーの値が違う問題を修正
Expand Down
51 changes: 46 additions & 5 deletions packages/backend/scripts/check_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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