连接超时HTTP put请求



我在GitHub上遇到了一个非常好的项目,我想尝试一下,但它并没有完全正常工作:https://github.com/jack3898/discord-youtube-bot-2

这是一个支持YouTube的Discord音乐机器人,它使用docker、docker compose和redis,这三件事在我几天前第一次发现它时对我来说都是新的。

在Windows上使用docker和docker compose时,这个机器人的工作原理很有魅力,但当我试图在Debian 11服务器上运行它时,问题就来了。

Creating redis ... done
Creating bot   ... done
Attaching to redis, bot
redis    | 1:C 17 Jan 2022 19:40:56.879 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis    | 1:C 17 Jan 2022 19:40:56.879 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis    | 1:C 17 Jan 2022 19:40:56.880 # Configuration loaded
redis    | 1:M 17 Jan 2022 19:40:56.881 * monotonic clock: POSIX clock_gettime
redis    | 1:M 17 Jan 2022 19:40:56.884 * Running mode=standalone, port=6379.
redis    | 1:M 17 Jan 2022 19:40:56.884 # Server initialized
redis    | 1:M 17 Jan 2022 19:40:56.884 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis    | 1:M 17 Jan 2022 19:40:56.886 * <ReJSON> version: 20006 git sha: db3329c branch: heads/v2.0.6
redis    | 1:M 17 Jan 2022 19:40:56.886 * <ReJSON> Exported RedisJSON_V1 API
redis    | 1:M 17 Jan 2022 19:40:56.895 * <ReJSON> Enabled diskless replication
redis    | 1:M 17 Jan 2022 19:40:56.895 * <ReJSON> Created new data type 'ReJSON-RL'
redis    | 1:M 17 Jan 2022 19:40:56.896 * Module 'ReJSON' loaded from /usr/lib/redis/modules/rejson.so
redis    | 1:M 17 Jan 2022 19:40:56.899 * <search> Redis version found by RedisSearch : 6.2.5 - oss
redis    | 1:M 17 Jan 2022 19:40:56.899 * <search> RediSearch version 2.2.5 (Git=v1.99.5-386-g93a916c4)
redis    | 1:M 17 Jan 2022 19:40:56.899 * <search> Low level api version 1 initialized successfully
redis    | 1:M 17 Jan 2022 19:40:56.900 * <search> concurrent writes: OFF, gc: ON, prefix min length: 2, prefix max expansions: 200, query timeout (ms): 500, timeout policy: return, cursor read size: 1000, cursor max idle (ms): 300000, max doctable size: 1000000, max number of search results:  1000000, search pool size: 20, index pool size: 8,
redis    | 1:M 17 Jan 2022 19:40:56.905 * <search> Initialized thread pool!
redis    | 1:M 17 Jan 2022 19:40:56.905 * <search> Acquired RedisJSON_V1 API
redis    | 1:M 17 Jan 2022 19:40:56.906 * <search> Enabled diskless replication
redis    | 1:M 17 Jan 2022 19:40:56.906 * Module 'search' loaded from /usr/lib/redis/modules/redisearch.so
redis    | 1:M 17 Jan 2022 19:40:56.907 * Ready to accept connections
bot      |
bot      | > discord-youtube-bot-2@1.0.0 bot
bot      | > cross-env NODE_ENV=production ts-node src/index.ts -p tsconfig.builds.json
bot      |
bot      | Environment: production
bot      | Redis host: redis
bot      | Bot logged in as MusicBOT!
bot      | Started refreshing application slash commands.
bot      | 19 unique commands have been found on the file system.
bot      | /home/app/node_modules/@node-redis/client/dist/lib/client/socket.js:163
bot      |             socket.setTimeout(__classPrivateFieldGet(this, _RedisSocket_options, "f").connectTimeout, () => socket.destroy(new errors_1.ConnectionTimeoutError()));
bot      |                                                                                                                            ^
bot      | ConnectionTimeoutError: Connection timeout
bot      |     at Socket.<anonymous> (/home/app/node_modules/@node-redis/client/dist/lib/client/socket.js:163:124)
bot      |     at Object.onceWrapper (node:events:509:28)
bot      |     at Socket.emit (node:events:390:28)
bot      |     at Socket.emit (node:domain:475:12)
bot      |     at Socket._onTimeout (node:net:501:8)
bot      |     at listOnTimeout (node:internal/timers:557:17)
bot      |     at processTimers (node:internal/timers:500:7)

正如你所看到的,它基本上是崩溃的错误";连接超时";。经过对代码的快速挖掘,我发现它在HTTP请求时崩溃了。(底部第二行代码(

import { REST } from '@discordjs/rest';
import { config, globals } from 'bot-config';
import { Routes } from 'discord-api-types/v9';
import fs from 'fs';
import path from 'path';
/**
* This function registers all slash commands to the Discord API.
* It also stores all command classes in the globals object to be used later.
*/
export async function registerCommands() {
const { discordToken, clientId, devGuildId } = config;
const rest = new REST({ version: '9' }).setToken(discordToken as string);
console.log('Started refreshing application slash commands.');
// Create an endpoint to the Discord API that has the relevant Bot ID.
// If not in production, the development Guild ID is added to speed up the command registration process.
const route =
config.environment === 'production'
? Routes.applicationCommands(clientId as string)
: Routes.applicationGuildCommands(clientId as string, devGuildId as string);
// This section simply finds all command classes.
const commandModulePath = path.resolve('src', 'commands', 'modules');
const commandModuleResolvingEntries = fs.readdirSync(commandModulePath).map(async moduleName => {
const module = await import(`${commandModulePath}/${moduleName}`);
return [moduleName, module];
});
const commandModules = await Promise.all(commandModuleResolvingEntries);
// Register all commands to the Discord API and add the commands to the globals commandModules Map() instance.
const slashCommandRegistrations = commandModules.map(module => {
const commandName = module[0].split('.')[0].toLowerCase(); // Remove the '.ts' at the end and force lowercase.
const commandClass = module[1].default;
globals.commandModules.set(commandName, commandClass);
return new commandClass().register().toJSON();
});
console.log(`${globals.commandModules.size} unique commands have been found on the file system.`);
// Send a HTTP PUT request to the Discord API to register all slash commands.
await rest.put(route, { body: slashCommandRegistrations });
console.log('Successfully reloaded application slash commands.');
}

我真的不知道是什么导致了这样的问题。这可能只是一些我看不见的新手。

谢谢你抽出时间。

全部解决!

这个问题与声明多个Redis客户端有关。

Cache.tsQueueManager.ts之间可以找到两个。只需要创建一个Redis客户端,就可以消除超时问题。

我觉得我有点不好的做法!但我学到了一些新东西。

最新更新