Skip to content

Conversation

@jlucaso1
Copy link
Collaborator

closes: #2104

Tested with direct file url, direct file path, node and bun.

@whiskeysockets-bot
Copy link
Contributor

whiskeysockets-bot commented Nov 28, 2025

Thanks for opening this pull request and contributing to the project!

The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch.

In the meantime, anyone in the community is encouraged to test this pull request and provide feedback.

✅ How to confirm it works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@WhiskeySockets/Baileys#fix-leak-upload

# Yarn (v2+)
yarn add @whiskeysockets/baileys@WhiskeySockets/Baileys#fix-leak-upload

# PNPM
pnpm add @whiskeysockets/baileys@WhiskeySockets/Baileys#fix-leak-upload

If you encounter any issues or have feedback, feel free to comment as well.

logger
)

if (result?.url || result?.directPath) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directPath instead direct_path maybe was a mispelling of using any type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an interesting bug

})
}

const uploadWithFetch = async ({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purpshell I created these two approaches because this is a bug in Node.js, so when it's fixed, we can remove the http/https approach. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems fine to pass for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

media uploads should be on https though 1000% of the time, maybe throw an error if not? Weird to be uploading media to a E2EE service over http :V

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@purpshell this is to be used in tests hahaha (We up a http server for this). But I can remove if is really a problem

@YonkoSam
Copy link
Contributor

Why do we cache downloads that take up so much memory for no real benefit? It would be better to just download them again rather than bringing the server down every few minutes.

@jlucaso1
Copy link
Collaborator Author

Why do we cache downloads that take up so much memory for no real benefit? It would be better to just download them again rather than bringing the server down every few minutes.

I don't get it. This PR is related to upload only

@YonkoSam
Copy link
Contributor

YonkoSam commented Nov 28, 2025

I know I’m not talking about this PR I’m talking about this.

   if (cacheableKey) {
        const mediaBuff = await options.mediaCache.get(cacheableKey);
        if (mediaBuff) {
            logger?.debug({ cacheableKey }, 'got media cache hit');
            const obj = proto.Message.decode(mediaBuff);
            const key = `${mediaType}Message`;
            Object.assign(obj[key], { ...uploadData, media: undefined });
            return obj;
        }
    }

@jlucaso1
Copy link
Collaborator Author

@YonkoSam This is not enabled by default (you need to explicit enable in sock config) and we are not storing the download content data (bytes of the image or video), only the protobuf metadata things like mediaKey, url, etc.

@YonkoSam
Copy link
Contributor

@jlucaso1 okey so the memory leak when uploading media comes from a different place

@jlucaso1 jlucaso1 marked this pull request as ready for review November 29, 2025 03:50
@AmilaPrabathKumara
Copy link

Thanks for the update!

I tested the changes on the fix-leak-upload branch, and I can confirm that the memory leak issue with large files is 100% resolved. The RAM usage is stable now during large uploads.

However, I noticed a new regression with this fix: Image and Audio messages are failing to send.

It seems only large document uploads are working fine, but standard media messages (images/audio) are not going through. Is there something specific regarding the media upload logic that was changed for these types?

@jlucaso1

@jlucaso1
Copy link
Collaborator Author

@AmilaPrabathKumara I need to check this. Thanks

@AmilaPrabathKumara
Copy link

@AmilaPrabathKumara I need to check this. Thanks

Okay, thanks. Let me know if you need any logs or further testing from my side.

@jlucaso1
Copy link
Collaborator Author

@AmilaPrabathKumara, could you try again? Actually, that was a regression, but it's fixed now (I added a test case to ensure it doesn't happen again). Thank you for helping with the testing.

@AmilaPrabathKumara
Copy link

@AmilaPrabathKumara, could you try again? Actually, that was a regression, but it's fixed now (I added a test case to ensure it doesn't happen again). Thank you for helping with the testing.

🤩 Thank you for the update! I just finished testing, and I can confirm the fix works perfectly.

​I tested with Images, Videos, Audio/PTT, and Documents — everything sends correctly now. Large file handling is also back to normal with stable memory usage.

​Since this resolves the regression completely, I hope this can be merged into master soon so everyone can benefit from the fix. Great work! 🚀

Thanks ❤️ @jlucaso1

@jlucaso1 jlucaso1 marked this pull request as draft December 3, 2025 14:20
@jlucaso1 jlucaso1 marked this pull request as ready for review December 3, 2025 14:28
@lopesclayton
Copy link
Contributor

Any updates or an estimated date to release this in RC10?

@purpshell purpshell merged commit 43d1787 into master Dec 6, 2025
4 checks passed
@purpshell
Copy link
Member

Any updates or an estimated date to release this in RC10?

It got merged into master now, RC10 is in a few days, so please test till then and report any bugs before we release the version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Memory Leak Regression when sending large media (Stream/URL) in v7.0.0-rc.8 & rc.9

8 participants