Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Duplicate txn.call_after calls when transactions are retried #12184

Closed
squahtx opened this issue Mar 8, 2022 · 3 comments · Fixed by #12315
Closed

Duplicate txn.call_after calls when transactions are retried #12184

squahtx opened this issue Mar 8, 2022 · 3 comments · Fixed by #12315
Labels
P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@squahtx
Copy link
Contributor

squahtx commented Mar 8, 2022

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.

@squahtx squahtx added S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Mar 8, 2022
@clokep
Copy link
Member

clokep commented Mar 9, 2022

Does this need discussion of what the proper behavior should be?

@squahtx
Copy link
Contributor Author

squahtx commented Mar 9, 2022

Probably? Let's stick it in the needs-discussion bucket.

@callahad
Copy link
Contributor

Conclusion from meeting: let's note this behavior in in the call_* function docstrings, but leave the behavior unchanged.

There are legitimate uses for both modalities, so if we wanted to address it we'd likely want to extend the API surface to indicate whether duplicate callbacks should be enqueued or not. But we'll hold off on that until we have a concrete motivation to make the change.

@callahad callahad added P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches and removed X-Needs-Discussion labels Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P4 (OBSOLETE: use S- labels.) Okay backlog: will not schedule, will accept patches S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants