fix: keep deferred collection state alive across drops by alexmac · Pull Request #2934 · typesense/typesense · GitHub
Skip to content

fix: keep deferred collection state alive across drops#2934

Open
alexmac wants to merge 1 commit into
typesense:v31from
alexmac:alex/drop-deferred-state-lifetime
Open

fix: keep deferred collection state alive across drops#2934
alexmac wants to merge 1 commit into
typesense:v31from
alexmac:alex/drop-deferred-state-lifetime

Conversation

@alexmac

@alexmac alexmac commented May 29, 2026

Copy link
Copy Markdown

Change Summary

Bug: deferred export/delete request state stored a raw Collection*. If a chunked export or delete paused, then the collection was dropped before the next chunk, the manager could destroy Collection -> Index -> num_tree_t while the request state still held a dangling pointer. This results in a use-after-free crash on the next deferred chunk when stateful_export_docs or stateful_remove_docs touches the freed Collection, or it could corrupt memory and later show up during Index / num_tree_t destruction like the stack trace.

Fix: export_state_t and deletion_state_t now hold std::shared_ptr in core_api_utils.h (line 10), and the route handlers store the request’s shared pointer in core_api.cpp (line 1489) and core_api.cpp (line 2212). That keeps the collection alive until the deferred request state is destroyed.

PR Checklist

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.

2 participants