Skip to content

fix: register SubXactCallback for subtransaction abort cleanup #269

@tjgreen42

Description

@tjgreen42

Summary

We register a XactCallback (for top-level transaction abort) but have no SubXactCallback. This causes issues when a subtransaction that created a BM25 index is rolled back via ROLLBACK TO SAVEPOINT:

  1. Registry/shared memory leak: The OAT_DROP hook doesn't fire during subtransaction abort, so the registry entry and shared DSA memory for the index are never cleaned up.

  2. LWLock tracking desync: If an error occurs during a BM25 scan inside a savepoint (between tp_acquire_index_lock and tp_release_index_lock), LWLockReleaseAll releases the lock during abort but our lock_held flag remains true. Since the XactCallback only fires on top-level abort, the desync persists until the top-level transaction ends.

Fix

Register a SubXactCallback in _PG_init that:

  • On SUBXACT_EVENT_ABORT_SUB: clean up build mode state (like tp_cleanup_build_mode_on_abort), reset lock_held tracking, and clean up registry entries for indexes created in the aborted subtransaction.

Found during investigation of #247.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions