-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Duplicate txn.call_after
calls when transactions are retried #12184
Description
Synapse provides the ability for database transactions to defer some processing until after the transaction succeeds or fails, via the Cursor.call_after
and Cursor.call_on_exception
methods. These methods append the given callback to an internal list which gets run once the transaction is done.
When a transaction fails with a SerializationFailure, Synapse will retry it up to 5 times (inside new_transaction
). Although a new Cursor is created for each attempt, the same after_callbacks
list is reused. This means that if a transaction fails, then succeeds on the next attempt, the after_callbacks
from the previous failed attempt will also run.
These callbacks are mostly used for cache invalidation, so this is probably okay?
Note that MultiWriterIdGenerator needs either the call_after
or call_on_exception
callbacks from failed transaction attempts to run, otherwise it wouldn't know when the ids handed out to failed transactions are done. If we were to clear out after_callbacks
in between attempts, MultiWriterIdGenerator would break.