Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: EBUSY: resource busy or locked #3072

Open
1 task done
justoverclockl opened this issue Jun 1, 2024 · 20 comments · Fixed by varreltantio/whatsapp-web.js#1 · May be fixed by #2661
Open
1 task done

Error: EBUSY: resource busy or locked #3072

justoverclockl opened this issue Jun 1, 2024 · 20 comments · Fixed by varreltantio/whatsapp-web.js#1 · May be fixed by #2661
Labels
bug Something isn't working

Comments

@justoverclockl
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

N.B. this not happen with previous versions of WWEBJS...happen with exodus package

I can get the qrcode and pairing code correctly, but after a qrcode scan i get

...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:47
            await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
            ^
Error: Error: EBUSY: resource busy or locked, unlink '...\server\.wwebjs_auth\session-adminSession\Default\chrome_debug.log'
    at ...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:49:27
    at LocalAuth.logout (...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:47:13)
    at ...\server\node_modules\whatsapp-web.js\src\Client.js:345:17

this is my client:

const authStrategy = new LocalAuth({
      clientId: 'adminSession',
    });

this.client = new Client({
      authStrategy,
      webVersion: '2.2412.50',
      webVersionCache: {
        remotePath:
          'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.50.html',
        type: 'remote',
      },
      takeoverOnConflict: true,
      puppeteer: {
        headless: true,
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
      },
    });

Expected behavior

as previous versions, i shouldn't get this error and the phone will be paired correctly.

Steps to Reproduce the Bug or Issue

  1. on Windows, start the server
  2. request qr code
  3. scan qrcode
  4. get the error
...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:47
            await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
            ^
Error: Error: EBUSY: resource busy or locked, unlink '...\server\.wwebjs_auth\session-adminSession\Default\chrome_debug.log'
    at ...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:49:27
    at LocalAuth.logout (...\server\node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js:47:13)
    at ...\server\node_modules\whatsapp-web.js\src\Client.js:345:17

Relevant Code

seems that the problem is here (based on che stack error)

async logout() {
if (this.userDataDir) {
await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
.catch((e) => {
throw new Error(e);
});
}
}

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

No, I am not using Multi Device

Environment

OS: Windows
whatsapp-web.js version: "whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#webpack-exodus"
node version: 18.17.1 and 20.12.2

Additional context

No response

@justoverclockl justoverclockl added the bug Something isn't working label Jun 1, 2024
@justoverclockl justoverclockl changed the title New bug with exodus Error: EBUSY: resource busy or locked, unlink with EXODUS Jun 1, 2024
@claudiogg88
Copy link

any solution?

@sauqi28
Copy link

sauqi28 commented Jun 3, 2024

any solution?

note yet, i have same problem

@aangwie
Copy link

aangwie commented Jun 4, 2024

any solution?

Try This. Open Constants.js at util folder, change this code
WebVersion : 2.2410.1, webVersionCache : { type : 'local' },

With This
webVersion: '2.2410.1', webVersionCache: { type: 'remote', remotePath : 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2410.1.html', },

@BernetteGunasekaran
Copy link

try this ,its working on windows

webVersion: '2.2322.15',
webVersionCache: {
type: 'remote',
remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html',

@claudiogg88
Copy link

I deleted all my messages and it didn't give any more errors

@justoverclockl
Copy link
Author

try this ,its working on windows

webVersion: '2.2322.15', webVersionCache: { type: 'remote', remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html',

not work at all...same error for me

@maaelphd
Copy link

maaelphd commented Jun 4, 2024

try this ,its working on windows

webVersion: '2.2322.15', webVersionCache: { type: 'remote', remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html',

This version work for me, i was receving the error: "Node with given id does not belong to the document"
When i checked the Constants.js file it was using the version "2.2410.1", Looking on "https://github.com/wppconnect-team/wa-version/tree/main/html", looks like this versions is not maintened anymore. Change to this new version works fine.
However, it is a bit annoying to have to check the versions frequently, but at the moment it is working now!

@alechkos alechkos closed this as completed Jun 7, 2024
@justoverclockl

This comment was marked as outdated.

@rizki5411
Copy link

anyone can fix it?

@justoverclockl
Copy link
Author

anyone can fix it?

no one will take care of issues (this is my experience so far). So maybe you need to wait for another version that address this (if you're lucky).

If this can help you this happen to me when i migrate to exodus...previous versions works....(for now)

@erenn44
Copy link

erenn44 commented Jun 11, 2024

anyone can fix it?

@claudiogg88
Copy link

anyone can fix it?

I was able to resolve it by clearing all messages from the app on my phone

@MarcosWandenkolk
Copy link

Modify the logout() function in your Client.js as follows:

   async logout() {
        await this.pupPage.evaluate(() => {
            return window.Store.AppState.logout();
        });
        
	await this.pupPage.waitForFunction(() => !(window.Store.isLogoutInProgress), { timeout: 20000 });
        
        let maxDelay = 0;
        while (this.pupBrowser.isConnected() && (maxDelay < 10)) { // waits a maximum of 1 second before calling the AuthStrategy
            await new Promise(resolve => setTimeout(resolve, 100));
            maxDelay++; 
        }
        
        await this.authStrategy.logout();
    }

For more details see: 6d68da4

@MrJmpl3
Copy link

MrJmpl3 commented Jun 19, 2024

I think the problem is here:

await this.authStrategy.logout();

Why the logout function delete the user folder without close the browser before?

@jenilghevariya09
Copy link

jenilghevariya09 commented Jul 2, 2024

I have the same problem did anyone get the fix?

@max-programming
Copy link

This is somehow related to #3173
When you log out, you will notice the ready event is being fired and according to the issue, the authenticated event is also being fired

@jenilghevariya09
Copy link

Temporary Fix for Preventing User Session Deletion on Logout

For those experiencing issues with user sessions being deleted upon logout in whatsapp-web.js, you can implement a temporary fix by modifying the LocalAuth.js file.

Open the file located at:

node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js

Comment Out Session Deletion Code

Find the logout method and comment out the code that deletes the session folder:

async logout() {
    // if (this.userDataDir) {
    //     await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
    //         .catch((e) => {
    //             throw new Error(e);
    //         });
    // }
    console.log('==========> logout');
}

Delete Session Folder Manually on Disconnected EventInstead of deleting the session folder on logout, delete it when a disconnected event is fired with the conditions reason == 'NAVIGATION' || reason == 'LOGOUT'.

Add the following code to handle the disconnected event:

client.on("disconnected", async (reason) => {
    await client.destroy();
    if (reason == 'NAVIGATION' || reason == 'LOGOUT') {
        const folderPath = path.join(__dirname, `../../../.wwebjs_auth/session-${userId}`);
        fs.rm(folderPath, { recursive: true, force: true }, (err) => {
            if (err) {
                console.log(`Error deleting folder: ${err.message}`);
            } else {
                console.log('Folder deleted successfully');
            }
        });
    }
});

This will prevent the session folder from being deleted automatically on logout and will ensure it is deleted only when necessary.

@rizki5411
Copy link

Temporary Fix for Preventing User Session Deletion on Logout

For those experiencing issues with user sessions being deleted upon logout in whatsapp-web.js, you can implement a temporary fix by modifying the LocalAuth.js file.

Open the file located at:

node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js

Comment Out Session Deletion Code

Find the logout method and comment out the code that deletes the session folder:

async logout() {
    // if (this.userDataDir) {
    //     await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
    //         .catch((e) => {
    //             throw new Error(e);
    //         });
    // }
    console.log('==========> logout');
}

Delete Session Folder Manually on Disconnected EventInstead of deleting the session folder on logout, delete it when a disconnected event is fired with the conditions reason == 'NAVIGATION' || reason == 'LOGOUT'.

Add the following code to handle the disconnected event:

client.on("disconnected", async (reason) => {
    await client.destroy();
    if (reason == 'NAVIGATION' || reason == 'LOGOUT') {
        const folderPath = path.join(__dirname, `../../../.wwebjs_auth/session-${userId}`);
        fs.rm(folderPath, { recursive: true, force: true }, (err) => {
            if (err) {
                console.log(`Error deleting folder: ${err.message}`);
            } else {
                console.log('Folder deleted successfully');
            }
        });
    }
});

This will prevent the session folder from being deleted automatically on logout and will ensure it is deleted only when necessary.

please how to get ${userId} ?

@jenilghevariya09
Copy link

Temporary Fix for Preventing User Session Deletion on Logout
For those experiencing issues with user sessions being deleted upon logout in whatsapp-web.js, you can implement a temporary fix by modifying the LocalAuth.js file.
Open the file located at:
node_modules\whatsapp-web.js\src\authStrategies\LocalAuth.js
Comment Out Session Deletion Code
Find the logout method and comment out the code that deletes the session folder:

async logout() {
    // if (this.userDataDir) {
    //     await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
    //         .catch((e) => {
    //             throw new Error(e);
    //         });
    // }
    console.log('==========> logout');
}

Delete Session Folder Manually on Disconnected EventInstead of deleting the session folder on logout, delete it when a disconnected event is fired with the conditions reason == 'NAVIGATION' || reason == 'LOGOUT'.
Add the following code to handle the disconnected event:

client.on("disconnected", async (reason) => {
    await client.destroy();
    if (reason == 'NAVIGATION' || reason == 'LOGOUT') {
        const folderPath = path.join(__dirname, `../../../.wwebjs_auth/session-${userId}`);
        fs.rm(folderPath, { recursive: true, force: true }, (err) => {
            if (err) {
                console.log(`Error deleting folder: ${err.message}`);
            } else {
                console.log('Folder deleted successfully');
            }
        });
    }
});

This will prevent the session folder from being deleted automatically on logout and will ensure it is deleted only when necessary.

please how to get ${userId} ?

basically here userId is clientId.

authStrategy: new LocalAuth({
                clientId: userId, 
            }),

use your clientId instead of it.

@gilney-canaltelecom
Copy link

This is still happening on 1.2.6...

error1

code1

It seems like the lib is calling logout on page change, which means its trying to delete puppeteer' data while the browser is still open, which causes the error...

I guess one option would be to stop the browser, call logout and then start it all over again!?

@alechkos alechkos changed the title Error: EBUSY: resource busy or locked, unlink with EXODUS Error: EBUSY: resource busy or locked Sep 26, 2024
@alechkos alechkos reopened this Sep 26, 2024
@alechkos alechkos linked a pull request Sep 26, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.