Skip to content

Conversation

@pifopi
Copy link
Contributor

@pifopi pifopi commented Dec 14, 2025

Hello !

It's related to the memory issue I reported on discord. The root cause is that a http_request ptr is stored in several lambda but the lifecycle of the lambda is bigger than the life of http_request

This one is fine [processor, rv, hci, this, owner, start, _url](https_client* client) {
This one isn't owner->queue_work(0, [owner, this, result, hci, _url]() {

In the second lambda and depending on when you shutdown dpp (if you do it very early, before shards are started), you will delete this http_request before the lambda finish and then it's undefined behaviour as you kept a this ptr. I tried to make a shared_ptr implementation to fix that but it's leaking memory like crazy (like before the fix that created this crash 0d5e932). I then tested this wait for completion and it works. I added custom logs to confirm that the wait saved me from crashing

http_request::outer lambda start :dpp::http_request@0x19770c20af0: completed=false
http_request::outer lambda stop :dpp::http_request@0x19770c20af0: completed=false
http_request::inner lambda start :dpp::http_request@0x19770c20af0: completed=false
http_request::inner lambda stop :dpp::http_request@0x19770c20af0: completed=true
http_request::outer lambda start :dpp::http_request@0x19770bde310: completed=false
http_request::outer lambda stop :dpp::http_request@0x19770bde310: completed=false`
http_request::inner lambda start :dpp::http_request@0x19770bde310: completed=false
[Sun Dec 14 16:04:05 2025] DEBUG: Cluster: 998 of 1000 session starts remaining
[Sun Dec 14 16:04:05 2025] INFO: Auto Shard: Bot requires 1 shard
[Sun Dec 14 16:04:05 2025] DEBUG: Starting with 1 shards...
[Sun Dec 14 16:04:05 2025] DEBUG: Connecting new session...
[Sun Dec 14 16:04:05 2025] INFO: Shard id 0 (1/1) ready!
[Sun Dec 14 16:04:05 2025] DEBUG: Resume URL for session cccfaf4f25ad5336dfdbbc1c9c8ad29d is wss://gateway-us-east1-d.discord.gg (host: gateway-us-east1-d.discord.gg)
http_request::~http_request begin this:dpp::http_request@0x19770c20af0: completed=true
http_request::~http_request end this:dpp::http_request@0x19770c20af0: completed=true
http_request::~http_request begin this:dpp::http_request@0x19770bde310: completed=false
[Sun Dec 14 16:04:10 2025] DEBUG: Shards started.
http_request::inner lambda stop :dpp::http_request@0x19770bde310: completed=true
http_request::~http_request end this:dpp::http_request@0x19770bde310: completed=true

Code change checklist

  • I have ensured that all methods and functions are fully documented using doxygen style comments.
  • My code follows the coding style guide.
  • I tested that my change works before raising the PR.
  • I have ensured that I did not break any existing API calls.
  • I have not built my pull request using AI, a static analysis tool or similar without any human oversight.

@netlify
Copy link

netlify bot commented Dec 14, 2025

Deploy Preview for dpp-dev ready!

Name Link
🔨 Latest commit d34fd5d
🔍 Latest deploy log https://app.netlify.com/projects/dpp-dev/deploys/69404d0318efe80008197008
😎 Deploy Preview https://deploy-preview-1523--dpp-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added documentation Improvements or additions to documentation code Improvements or additions to code. labels Dec 14, 2025
@pifopi
Copy link
Contributor Author

pifopi commented Dec 14, 2025

It is better than #1522 but I'm keeping both PR to be able to compare

@pifopi pifopi marked this pull request as draft December 16, 2025 00:37
@pifopi
Copy link
Contributor Author

pifopi commented Dec 16, 2025

Putting this as a draft while I figure out issues with unit tests

@pifopi pifopi closed this Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Improvements or additions to code. documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant