首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >连接超时HTTP请求

连接超时HTTP请求
EN

Stack Overflow用户
提问于 2022-01-17 19:58:17
回答 1查看 610关注 0票数 1

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

这是一个不和谐的音乐机器人,它支持YouTube,它使用的是码头,码头-写作和红色,所有这三件事是我在几天前第一次发现它是新的。

在Windows上使用对接和停靠组合时,机器人的工作方式很有魅力,但是当我试图在Debian 11服务器上运行它时,问题就出现了。

代码语言:javascript
运行
复制
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请求上崩溃了。(第二行代码从底部)

代码语言:javascript
运行
复制
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.');
}

我真的找不出是什么引起了这样的问题。这可能只是一些我看不到的菜鸟的东西。

耽误您时间,实在对不起。

EN

回答 1

Stack Overflow用户

发布于 2022-01-18 22:33:55

都解决了!

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

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70746842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档