fix: worker-safe index lifecycle; drop FFI backend, keep ext-php-rs only#1
Merged
Merged
Conversation
Two production blockers from the code review, plus removal of the FFI backend. Fix #1 — handle leak: nothing tied a registry entry's lifetime to the owning PHP object, so every open() without an explicit close() leaked an IndexState (mmap reader + segment FDs, and up to the writer heap) for the life of a PHP-FPM worker. Add `impl Drop for Index` (RAII release on GC) and an ExtClient::__destruct() as a deterministic, idempotent release point. Fix #2 — mutex poisoning: a panic inside a tantivy op under the global table lock poisoned the Mutex, and every later `.lock().unwrap()` then panicked, bricking all indexes in the worker. Route all lock sites through a lock_table() helper that recovers via PoisonError::into_inner() (the guarded HashMap can't be left half-updated by a panic in the user closure, so recovery is safe). Both fixes covered by new regression tests (registry poison recovery; ext Drop releases the handle), written test-first. Drop the FFI backend entirely (tantivy-ffi crate, C header, FfiClient) so only the ext-php-rs extension remains. The Client facade now delegates straight to ExtClient and errors with an actionable message when the extension isn't loaded (this also closes the FFI-only packaging finding). Updated CI, docs, composer. Also require IndexBusyException in the PHPUnit bootstrap (latent fatal). Verified: cargo build --release, cargo test (11 passed), clippy -D warnings, and the PHP smoke test against the built extension all green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two production blockers from the code review, plus removal of the FFI backend.
Fix #1 — handle leak: nothing tied a registry entry's lifetime to the owning PHP object, so every open() without an explicit close() leaked an IndexState (mmap reader + segment FDs, and up to the writer heap) for the life of a PHP-FPM worker. Add
impl Drop for Index(RAII release on GC) and an ExtClient::__destruct() as a deterministic, idempotent release point.Fix #2 — mutex poisoning: a panic inside a tantivy op under the global table lock poisoned the Mutex, and every later
.lock().unwrap()then panicked, bricking all indexes in the worker. Route all lock sites through a lock_table() helper that recovers via PoisonError::into_inner() (the guarded HashMap can't be left half-updated by a panic in the user closure, so recovery is safe).Both fixes covered by new regression tests (registry poison recovery; ext Drop releases the handle), written test-first.
Drop the FFI backend entirely (tantivy-ffi crate, C header, FfiClient) so only the ext-php-rs extension remains. The Client facade now delegates straight to ExtClient and errors with an actionable message when the extension isn't loaded (this also closes the FFI-only packaging finding). Updated CI, docs, composer. Also require IndexBusyException in the PHPUnit bootstrap (latent fatal).
Verified: cargo build --release, cargo test (11 passed), clippy -D warnings, and the PHP smoke test against the built extension all green.