WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.1k stars 1.07k forks source link

EBUSY: resource busy or locked when sending message using buffer image #518

Closed arpitgoyall closed 4 months ago

arpitgoyall commented 7 months ago

Describe the bug When we try to send a message containing an image buffer then it gives the error shown below:

{
  "level": 50,
  "time": "2023-11-28T14:18:32.266Z",
  "pid": 10392,
  "hostname": "ZERO_BOOK_13",
  "err": {
    "type": "Error",
    "message": "EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "stack": "Error: EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "errno": -4082,
    "code": "EBUSY",
    "syscall": "unlink",
    "path": "C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB"
  },
  "msg": "An error occured during message send"
}

To Reproduce Steps to reproduce the behavior:

Send message that contains an image buffer

await socket.sendMessage(jid,
    {
      image: Buffer.from(imageBase64, 'base64'),
      caption: "This is caption",
    }
);

Expected behavior The message should be delivered without any errors.

Additional context I also tried saving the file into the disk and passing the path of it like { image: { url : "path/to/file"} } but the same problem is coming when we try to delete that file, obviously we don't want to store those images forever.

CSFelix commented 7 months ago

Same problem here. It happens when I try to send images on webp format like the two compacted images below:

Backgrounds.zip

CSFelix commented 7 months ago

I have good (or bad) news!!

In my case, the problem happens when I let the jpegThumbnail for images be automatically generated by jimp package. When I manually set the property as an empty string for instance, the problem does not happen:

options = {
        image: fs.readFileSync(media.path),
        caption: body,
        jpegThumbnail: ""
};

But, the images are sent without a thumbnail (expected, since I set the thumbnail as an empty string):

image


Then, I would guess the issue is in Jimp package when it tries to automatically generate the thumbnail.

I am studying about it and I'll let you know when I find a solution.

CSFelix commented 7 months ago

I was able to solve the problem temporally using this workaround:

options = {
  image: fs.readFileSync(media.path),
  caption: formatBody(body as string, ticket.contact)
};

let sentMessage;
try {
  sentMessage = await wbot.sendMessage(number, { ...options });
} catch (err) {
  options = {
    image: fs.readFileSync(media.path),
    caption: formatBody(body as string, ticket.contact),
    jpegThumbnail: ""
  };
  sentMessage = await wbot.sendMessage(number, { ...options });
}

Now, I'm searching how to completely solve it (send webp images with automatically generated thumbnails)

raseldev18 commented 7 months ago

Describe the bug When we try to send a message containing an image buffer then it gives the error shown below:

{
  "level": 50,
  "time": "2023-11-28T14:18:32.266Z",
  "pid": 10392,
  "hostname": "ZERO_BOOK_13",
  "err": {
    "type": "Error",
    "message": "EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "stack": "Error: EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "errno": -4082,
    "code": "EBUSY",
    "syscall": "unlink",
    "path": "C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB"
  },
  "msg": "An error occured during message send"
}

To Reproduce Steps to reproduce the behavior:

Send message that contains an image buffer

await socket.sendMessage(jid,
    {
      image: Buffer.from(imageBase64, 'base64'),
      caption: "This is caption",
    }
);

Expected behavior The message should be delivered without any errors.

Additional context I also tried saving the file into the disk and passing the path of it like { image: { url : "path/to/file"} } but the same problem is coming when we try to delete that file, obviously we don't want to store those images forever.

maybe this solves your problem: https://github.com/BochilGaming/games-wabot-md/blob/e6d5e830bc438a26437f303e2f1aeadc86c05c85/lib/clearTmp.js#L28

CSFelix commented 7 months ago

Describe the bug When we try to send a message containing an image buffer then it gives the error shown below:

{
  "level": 50,
  "time": "2023-11-28T14:18:32.266Z",
  "pid": 10392,
  "hostname": "ZERO_BOOK_13",
  "err": {
    "type": "Error",
    "message": "EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "stack": "Error: EBUSY: resource busy or locked, unlink 'C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB'",
    "errno": -4082,
    "code": "EBUSY",
    "syscall": "unlink",
    "path": "C:\\Users\\arpit\\AppData\\Local\\Temp\\imageBAE5545C74E3D4DB"
  },
  "msg": "An error occured during message send"
}

To Reproduce Steps to reproduce the behavior: Send message that contains an image buffer

await socket.sendMessage(jid,
    {
      image: Buffer.from(imageBase64, 'base64'),
      caption: "This is caption",
    }
);

Expected behavior The message should be delivered without any errors. Additional context I also tried saving the file into the disk and passing the path of it like { image: { url : "path/to/file"} } but the same problem is coming when we try to delete that file, obviously we don't want to store those images forever.

maybe this solves your problem: https://github.com/BochilGaming/games-wabot-md/blob/e6d5e830bc438a26437f303e2f1aeadc86c05c85/lib/clearTmp.js#L28

Did not work for me 😢

CSFelix commented 6 months ago

Any updates on this bug?

arpitgoyall commented 4 months ago

Issue was resolved when I used this code

await socket.sendMessage(jid,
    {
      image: Buffer.from(imageBase64, 'base64'),
      caption: "This is caption",
      jpegThumbnail: '',
    }
);

jpegThumbnail parameter makes the difference