OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

  • Thread starter Thread starter luckypenny
  • Start date Start date
L

luckypenny

Guest
I am developing a telegram bot following the tutorial and the code is working as I want. But there is a warning.

Code:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit

I found a solution via stackoverflow.

Code:
require('events').EventEmitter.defaultMaxListeners = 15;

I understand that removing the restriction will remove the warning, but not the cause, and you will not receive any alerts about the cause of the resource leak. But I can't know the reason in my code. This is my code:

Code:
const { Bot, InlineKeyboard } = require("grammy");

// Create a bot using the Telegram token
const bot = new Bot(process.env.HTTP_API_TOKEN || "");

const introductionMessage = `Hello! Welcome to Bot`;

const aboutUrlKeyboard = new InlineKeyboard();
aboutUrlKeyboard.row().webApp(
"Play",
"https://www.google.com/"
);

const replyWithIntro = (ctx) =\>
ctx.reply(introductionMessage, {
reply_markup: aboutUrlKeyboard,
parse_mode: "HTML",
});

// Keep this at the bottom of the file
bot.command("start", replyWithIntro);
bot.command("help", replyWithIntro);
bot.on("message", replyWithIntro);

bot.start();

<p>I am developing a telegram bot following the tutorial and the code is working as I want. But there is a warning.</p>
<pre><code>MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
</code></pre>
<p>I found a solution via stackoverflow.</p>
<pre><code>require('events').EventEmitter.defaultMaxListeners = 15;
</code></pre>
<p>I understand that removing the restriction will remove the warning, but not the cause, and you will not receive any alerts about the cause of the resource leak. But I can't know the reason in my code.
This is my code:</p>
<pre><code>const { Bot, InlineKeyboard } = require("grammy");

// Create a bot using the Telegram token
const bot = new Bot(process.env.HTTP_API_TOKEN || "");

const introductionMessage = `Hello! Welcome to Bot`;

const aboutUrlKeyboard = new InlineKeyboard();
aboutUrlKeyboard.row().webApp(
"Play",
"https://www.google.com/"
);

const replyWithIntro = (ctx) =\>
ctx.reply(introductionMessage, {
reply_markup: aboutUrlKeyboard,
parse_mode: "HTML",
});

// Keep this at the bottom of the file
bot.command("start", replyWithIntro);
bot.command("help", replyWithIntro);
bot.on("message", replyWithIntro);

bot.start();
</code></pre>
 

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top