pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.62k stars 3.48k forks source link

Whatsapp Web Perfomance Issue #2714

Closed tinyprocessing closed 6 months ago

tinyprocessing commented 6 months ago

### Is there an existing issue for this?

Describe the bug

Bug Report

Summary: Connecting the phone with 1000+ groups is causing disruptions, which was not an issue in the previous version. The platform normally receives new messages from the phone by handling the "onmessage" event and forwarding the data to the server.

Issue: After every 2 days, the bot starts disconnecting, necessitating a website reload and a subsequent 2-day wait. The problem seems to be rooted in Client.js, as it fails to respond to commands. The "onmessage" event becomes unresponsive, preventing the reception of new messages. Consequently, sending test messages to groups becomes impossible, resulting in significant lag.

Reproduction Steps: To reproduce the issue, attempt to work with an account that has a substantial load, particularly with 1000+ groups. The problem is not observed in smaller accounts (<300 groups), where messaging functions smoothly without the need for a reload.

Expected Behavior: The platform should handle large group loads (1000+ groups) without experiencing disruptions in the "onmessage" event, allowing continuous message reception and processing.

Actual Behavior: After approximately 2 days, the bot disconnects, and Client.js becomes unresponsive to commands. The "onmessage" event gets stuck, preventing the reception of new messages, ultimately causing lag in message processing.

Additional Information:

Docker state screenshot after 2 days: Screenshot 2024-01-10 at 16 32 50

Smaller accounts (<300 groups) do not exhibit the issue, functioning normally for extended periods without reloading. Your prompt attention to this matter and assistance in debugging the performance issues would be greatly appreciated.

Before the client is blocked, the status is as follows: No NAVIGATION.

Change status - OPENING Change status - PAIRING Change status - CONNECTED

Environment:

Platform Version: Android (Whatsapp) Client.js Version: v1.23.0 Browser: Chrome Operating: System: Docker, Ubuntu, Node.js FROM ubuntu:latest

Thank you for your assistance in resolving this issue promptly.

Expected behavior

The platform should handle large group loads (1000+ groups) without experiencing disruptions in the "onmessage" event, allowing continuous message reception and processing.

Steps to Reproduce the Bug or Issue

To reproduce the issue, attempt to work with an account that has a substantial load, particularly with 1000+ groups. The problem is not observed in smaller accounts (<300 groups), where messaging functions smoothly without the need for a reload.

Relevant Code


const TelegramBot = require('node-telegram-bot-api');
const { Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('./qrcode');
const telegram = require('./telegram');
const config = require('./config');
const arguments = require('./arguments');
const Settings = require('./network/settings');
const status = require('./client');
const messageWorker = require('./message');

const args = process.argv.slice(2);
if (args.length === 0) {
    console.error('Error: Missing argument. Please provide a value for BOT_ID.');
    process.exit(1);
}

arguments.parse(args[0], config);
console.log(config);

const telegramClient = new TelegramBot(config.telegram.token, { polling: true });
const options = { dataPath: './data/.wwebjs_auth/' };
const client = new Client({
    puppeteer: { headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox', '--unhandled-rejections=strict', '--disable-dev-shm-usage'] },
    authStrategy: new LocalAuth(options),
    webVersion: '2.2353.56'
});

// Initialize components
const settings = new Settings(telegramClient, config);

// Start Telegram
telegram(client, telegramClient, config, settings);

// Handle QR Code and Status
qrcode.listen(client, telegramClient, config);
status.listen(client, telegramClient, config);

// Loading screen message
client.on('loading_screen', (percent, message) => {
    telegramClient.sendMessage(config.telegram.userID, 'Loading... ' + percent + ' ' + message);
});

// Process incoming messages
client.on('message', async (message) => {
    messageWorker.createProcessMessagePromise(message, client, settings, config, telegramClient);
});

// Send initial message
telegramClient.sendMessage(config.telegram.userID, 'Application started');

// Update settings and send initial message
settings.updateAndSendMessage();

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Platform Version: Android (Whatsapp) Client.js Version: Latest Browser: Chrome Operating: System: Docker, Ubuntu, Node.js

Additional context

No response

tinyprocessing commented 6 months ago