Wait for http request completion with condition variable #1523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Code change checklist