Skip to main content

Function: registerRollbackHook()

registerRollbackHook(hook): void

Defined in: service-core/src/decorators/DatabaseDecorators.ts:45

Registers a best-effort compensating action to run if the currently active transaction (the one owning the ambient transactionContext) ultimately fails. Intended for code that just committed a write on a different connection than the active transaction's own (e.g. one that can't be rolled back by that transaction's own abort) and needs its own explicit cleanup to avoid an orphaned write if the active transaction later fails. A no-op if there's no active transaction to register against.

The hook is responsible for catching and logging its own errors; if it throws anyway, that's swallowed (via Promise.allSettled) rather than masking the original failure that triggered the rollback.

Parameters

hook

() => Promise<void>

The compensating action to run.

Returns

void