fix(plugin-search): surface sync write errors that silently roll back the parent transaction - #17725
Open
eeshsaxena wants to merge 1 commit into
Open
Conversation
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.
Fixes #17699.
Problem
syncDocAsSearchIndexruns the search-doccreate/update/deletecalls with the incomingreq, so they join the parent operation's transaction. Every write is wrapped in atry/catchthat logs and swallows the error. Under MongoDB, a failed write inside a transaction aborts the whole transaction, so the parent operation (e.g. a publish) rolls back — but because the error was swallowed,payload.create/payload.updateand the REST/GraphQL request resolve as if they succeeded. The editor sees their publish silently revert to the previously published version, with the only signal being a server log line.Fix
Errors from the search-doc writes are still logged, but they are now rethrown when both:
req.transactionIDis set), so a failed write has genuinely aborted the parent operation and reporting success would be wrong; andonSyncErroris not provided).That second condition keeps the change scoped to the document-lifecycle hook path (the publish in the issue). The reindex handler passes its own
onSyncErrorand manages its own transaction and per-collection recovery, so it stays best-effort exactly as before. When there is no shared transaction to abort (e.g. adapters running without one), the sync also stays best-effort and only logs.A small
WeakSetmakes sure each error object is logged once, so an error rethrown out of an innercatchand re-caught by an outer one keeps its original, most specific message instead of being relabelled.Result
For an indexed collection with a search-doc write failure inside the parent transaction, the parent operation now fails with the error surfaced to the caller instead of resolving successfully and silently reverting. The repro in
test/plugin-search-write-errors(a second publish that hits a unique-index conflict on the search collection) now either surfaces the error or persists, rather than doing neither.