wppconnect-team / wppconnect-server

Wppconnect Server is a ready-to-use API, just download, install, and start using, simple as that.
https://wppconnect.io/swagger/wppconnect-server/
Apache License 2.0
678 stars 396 forks source link

Unable to reconnect a device via userDataDir after server is shutdown #1844

Closed carlosdarwed closed 5 months ago

carlosdarwed commented 6 months ago

Description

When trying to reconnect a session from the userDataDir using the route start-session, an error about chromium locking the profile because multiple processes were going on the same profile happens, eventually, the qrCode appears and you can try to connect the device, but if you don't, then the device becomes useless, you can't regenerate it's QrCode and reconnect it anymore, it turns into a ghost.

Environment

// eslint-disable-next-line @typescript-eslint/no-var-requires require('dotenv').config();

export default { secretKey: 'THISISMYSECURETOKEN', host: 'http://localhost', port: '21465', deviceName: 'device name', poweredBy: 'powered by', startAllSession: true, tokenStoreType: 'mongodb', privateDb: true, maxListeners: 15, customUserDataDir: './userDataDir/', webhook: { url: null, autoDownload: true, uploadS3: false, readMessage: true, allUnreadOnStart: false, listenAcks: true, onPresenceChanged: true, onParticipantsChanged: true, onReactionMessage: true, onPollResponse: true, onRevokedMessage: true, onLabelUpdated: true, onSelfMessage: false, }, chatwoot: { sendQrCode: true, sendStatus: true, }, archive: { enable: true, waitTime: 10, daysToArchive: 45, }, log: { level: 'silly', // Before open a issue, change level to silly and retry a action... logger: ['console', 'file'], }, createOptions: { whatsappVersion: '2.2412.54', browserArgs: [ '--disable-web-security', '--no-sandbox', '--disable-web-security', '--aggressive-cache-discard', '--disable-cache', '--disable-application-cache', '--disable-offline-load-stale-cache', '--disk-cache-size=0', '--disable-background-networking', '--disable-default-apps', '--disable-extensions', '--disable-sync', '--disable-translate', '--hide-scrollbars', '--metrics-recording-only', '--mute-audio', '--no-first-run', '--safebrowsing-disable-auto-update', '--ignore-certificate-errors', '--ignore-ssl-errors', '--ignore-certificate-errors-spki-list', ], }, mapper: { enable: false, prefix: 'tagone-', }, db: { mongodbDatabase: 'mongoDbDatabase', mongodbCollection: 'mongoDbCollection', mongodbUser: 'mongodbUser', mongodbPassword: 'mongodbPassword', mongodbHost: 'mongodbhost', mongoIsRemote: true, mongoURLRemote: process.env.MONGODB_URL_CONN, mongodbPort: 27017, redisHost: 'localhost', redisPort: 6379, redisPassword: '', redisDb: 0, redisPrefix: 'docker', }, aws_s3: { region: 'sa-east-1', access_key_id: null, secret_key: null, defaultBucketName: null, }, };

Steps to Reproduce

  1. Turn on the the server in any server
  2. Connect a device via QrCode (Using my config, you should store this session in the userDataDir)
  3. Wait for it to be connected
  4. Shutdown the Server
  5. Turn the server on again
  6. Try to reconnect using the function start-session

Log Output

If relevant, paste all of your Log Output

error: [a98a79f7-8d5d-48b7-b4fc-18f31ae552c7:browser] Error no open browser error: [a98a79f7-8d5d-48b7-b4fc-18f31ae552c7:browser] Failed to launch the browser process! undefined [35:35:0507/183032.559839:ERROR:process_singleton_posix.cc(353)] another Chromium process (24) on another computer (goalwata-dev-7986f86bc-n6tlw). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium. [35:35:0507/183032.566728:ERROR:message_box_dialog.cc(146)] Unable to show a dialog outside the UI thread message loop: Chromium - The profile appears to be in use by another Chromium process (24) on another computer (goalwata-dev-7986f86bc-n6tlw). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium.

TROUBLESHOOTING: https://pptr.dev/troubleshooting

error: 2024-05-07T18:30:32.681Z Failed to launch the browser process! undefined [35:35:0507/183032.559839:ERROR:process_singleton_posix.cc(353)] The profile appears to be in use by another Chromium process (24) on another computer (goalwata-dev-7986f86bc-n6tlw). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium. [35:35:0507/183032.566728:ERROR:message_box_dialog.cc(146)] Unable to show a dialog outside the UI thread message loop: Chromium - The profile appears to be in use by another Chromium process (24) on another computer (goalwata-dev-7986f86bc-n6tlw). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium.

Your Code

Not so relevant, it's basically some business rules added, if device is not on clientsArray or if it's status is "disconnected", then try to reconnect it via Axios call

Additional context / Screenshot

Add any other context about the problem here. If applicable, add screenshots to help explain.

I run this application in GCP, in a kubernetes cluster, containerizing it with Docker

One of the business rules of the system is if the server is somehow restarted, when online again, it should reconnect all the devices one by one, if a device has the status "connected' in userDataDir, use the start-session to just reconnect it again, else, generate the QR code and leave it alone. Because of this bug, I'm not being able to accomplish this rule. I understand I do not have a "priority pass" for being attended immediately, but I would appreciate it if the development team gave some attention to this, it's really important because it's preventing our custom system from improving.

image

nestorcde commented 6 months ago

same problem here.

omladalan commented 5 months ago

I managed to get around the problem, but for now only by running shell commands.

Researching the subject, the problem is due to the SingletonLock file in /usr/src/wpp-server/userDataDir/{mySession}/ I deleted it before turning off the container, when I turned it back on the session was connected normally.

I'm new to Docker, but if someone can make a script that runs before starting the node server to delete this file from all sessions, it will definitely solve the problem.

image

To access the container terminal I used the following command sudo docker exec -it {containerID} sh

renat473 commented 5 months ago

Delete for sessions