devlikeapro / waha

WAHA - WhatsApp HTTP API (REST API) that you can configure in a click! Two engines: chromium-based WEBJS and pure-websocket NOWEB
https://waha.devlike.pro/
Apache License 2.0
919 stars 277 forks source link

[BUG][WEBJS] - Error WhatsappSession #524

Closed D-erhan closed 2 weeks ago

D-erhan commented 2 weeks ago
[10:17:14.088] ERROR (WhatsappSession/49): session:default9 - Execution context was destroyed, most likely because of a navigation. {"reqId":1036148,"session":"default9","sessionRunTimestamp":1725272022494}
    err: {
      "type": "Error",
      "message": "Execution context was destroyed, most likely because of a navigation.",
      "stack":
          Error: Execution context was destroyed, most likely because of a navigation.
              at rewriteError (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:284:15)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async ExecutionContext._ExecutionContext_evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:227:56)
              at async ExecutionContext.evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
              at async WebjsClient.getWWebVersion (/app/node_modules/whatsapp-web.js/src/Client.js:812:16)
              at async WebjsClient.inject (/app/node_modules/whatsapp-web.js/src/Client.js:98:25)
              at async WebjsClient.inject (/app/dist/core/engines/webjs/WebjsClient.js:9:9)
              at async WebjsClient.initialize (/app/node_modules/whatsapp-web.js/src/Client.js:333:9)

And

[10:17:48.142] INFO (49): request errored {"reqId":1036385,"req":{"id":1036385,"method":"GET","url":"/api/contacts/profile-picture?&session=default12&contactId=exmaple%40c.us","query":{"session":"default12","contactId":"exmaple@c.us"},"params":{"0":"api/contacts/profile-picture"}},"res":{"statusCode":500},"responseTime":263}
    err: {
      "type": "Error",
      "message": "Evaluation failed: TypeError: Cannot read properties of undefined (reading 'getContact')\n    at pptr://__puppeteer_evaluation_script__:2:34",
      "stack":
          Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'getContact')
              at pptr://__puppeteer_evaluation_script__:2:34
              at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:229:15)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async ExecutionContext.evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
              at async WebjsClient.getContactById (/app/node_modules/whatsapp-web.js/src/Client.js:1100:23)
              at async WhatsappSessionWebJSPlus.getContactProfilePicture (/app/dist/core/engines/webjs/session.webjs.core.js:360:25)
    }
[10:17:48.522] INFO (WebhookSender/49): session:default19 - Sending POST to https://httpbin.org/post... {"reqId":848505,"session":"default19","sessionRunTimestamp":1724927190715}
[10:17:48.522] ERROR (WhatsappSession/49): session:default19 - The browser has been disconnected {"reqId":848505,"session":"default19","sessionRunTimestamp":1724927190715}
[10:17:48.522] INFO (WhatsappSession/49): session:default19 - Job scheduled with timeout 2000 ms {"reqId":848505,"session":"default19","sessionRunTimestamp":1724927190715,"job":"start-engine","class":"SingleDelayedJobRunner"}
[10:17:48.527] INFO (WebhookSender/49): session:default9 - Sending POST to https://httpbin.org/post... {"reqId":1036380,"session":"default9","sessionRunTimestamp":1725272246657}
[10:17:48.527] ERROR (WhatsappSession/49): session:default9 - Protocol error (Runtime.callFunctionOn): Target closed. {"reqId":1036380,"session":"default9","sessionRunTimestamp":1725272246657}
    err: {
      "type": "ProtocolError",
      "message": "Protocol error (Runtime.callFunctionOn): Target closed.",
      "stack":
          ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.
              at /app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
              at new Promise (<anonymous>)
              at CDPSessionImpl.send (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
              at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:211:46)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async ExecutionContext.evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16)
      "name": "ProtocolError",
      "originalMessage": ""
    }
D-erhan commented 2 weeks ago

if you run 4 sessions in a row, the previous failed ones are restarted and go back to failed

D-erhan commented 2 weeks ago

and spamming with this

[10:25:23.522] WARN (SessionManagerPlus/49): session:default9 - Error while getting engine info {"reqId":1036581,"session":"default9"}
    error: {}
[10:25:23.522] WARN (SessionManagerPlus/49): session:default56 - Error while getting engine info {"reqId":1036581,"session":"default56"}
    error: {}
[10:25:23.522] WARN (SessionManagerPlus/49): session:default57 - Error while getting engine info {"reqId":1036581,"session":"default57"}
    error: {}
[10:25:23.522] WARN (SessionManagerPlus/49): session:default58 - Error while getting engine info {"reqId":1036581,"session":"default58"}
    error: {}
D-erhan commented 2 weeks ago
[10:34:56.615] INFO (WhatsappSession/49): session:default61 - Job cancelled {"reqId":1036654,"session":"default61","sessionRunTimestamp":1725273200923,"job":"start-engine","class":"SingleDelayedJobRunner"}
[10:34:56.616] INFO (SessionManagerPlus/49): Session has been stopped. {"reqId":1036678}
[10:34:56.622] ERROR (WhatsappSession/49): session:default61 - Protocol error (Runtime.callFunctionOn): Target closed. {"reqId":1036654,"session":"default61","sessionRunTimestamp":1725273200923}
    err: {
      "type": "ProtocolError",
      "message": "Protocol error (Runtime.callFunctionOn): Target closed.",
      "stack":
          ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.
              at /app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
              at new Promise (<anonymous>)
              at CDPSessionImpl.send (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
              at ExecutionContext._ExecutionContext_evaluate (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:211:46)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async JSHandle.evaluateHandle (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/JSHandle.js:97:16)
              at async WaitTask.rerun (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WaitTask.js:114:28)
      "name": "ProtocolError",
      "originalMessage": ""
    }
[10:34:56.786] INFO (49): request errored {"reqId":1036677,"req":{"id":1036677,"method":"GET","url":"/api/screenshot?session=default61","query":{"session":"default61"},"params":{"0":"api/screenshot"}},"res":{"statusCode":500},"responseTime":3415}
    err: {
      "type": "ProtocolError",
      "message": "Protocol error (Page.captureScreenshot): Target closed.",
      "stack":
          ProtocolError: Protocol error (Page.captureScreenshot): Target closed.
              at /app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
              at new Promise (<anonymous>)
              at CDPSessionImpl.send (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
              at CDPPage._CDPPage_screenshotTask (/app/node_modules/whatsapp-web.js/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:2591:77)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      "name": "ProtocolError",
      "originalMessage": ""
    }
D-erhan commented 2 weeks ago

62-session WEBJS I start one session and 2-3 others are disconnected

devlikepro commented 2 weeks ago

Hi! Could you share the version you're using?

http://localhost:3000/api/version

patron:PRO

devlikepro commented 2 weeks ago

62-session

do you mean you're running 62 sessions or ..? How about CPU/Memory available on the server?

patron:PRO

D-erhan commented 2 weeks ago

2024.9.1

patron:PLUS

D-erhan commented 2 weeks ago

62sessions launched in total and this problem appeared after more than 50 sessions were launched, it turns out that when a new session is launched, other sessions are disconnected on their own and go into an endless restart Intel (R) Xeon (R) CPU E3-1275 v5 at 3.60 GHz of 62Gi RAM Swap: 31Gi patron:PLUS

devlikepro commented 2 weeks ago

I see, try scaling it to different workers, like for 50 for each container https://waha.devlike.pro/blog/waha-scaling-how-to-handle-500-sessions/

Never tested it with 50+ sessions with WEBJS in a single container, to be honest... Chromium+puppeter instances are pretty hard thing to deal with in large scale

patron:PRO

D-erhan commented 2 weeks ago

image

patron:PLUS