Skip to content

Wait for http request completion#1521

Closed
pifopi wants to merge 1 commit intobrainboxdotcc:masterfrom
pifopi:wait-http-request
Closed

Wait for http request completion#1521
pifopi wants to merge 1 commit intobrainboxdotcc:masterfrom
pifopi:wait-http-request

Conversation

@pifopi
Copy link
Copy Markdown
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 if 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.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 14, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution, but PRs must be raised against the dev branch. Please log your pull request against the dev branch not master. You can also retarget this pull request, then reopen it.

@github-actions github-actions Bot added the code Improvements or additions to code. label Dec 14, 2025
@github-actions github-actions Bot closed this Dec 14, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants