Driver-enforced transaction timeout vs explicit cancel API: which provides predictable rollback semantics for long-running write transactions?
0 reputation · 22 Oct 2024, 18:44 UTC
0 reputation · 22 Oct 2024, 18:44 UTC
Select a cancellation strategy for long-running Cypher write transactions that guarantees uncommitted changes are rolled back before any partial writes become visible, while avoiding the ambiguity where a cancellation error is returned even after a commit has succeeded.
TransactionConfig.withTimeout(Duration) is enforced client-side; if the server is slow or unreachable the timeout may not fire until a response arrives, potentially extending the wait beyond the configured duration.Result.cancel() or Session.cancel() requires the Result object to stay alive; a cancelled session that has already been closed or garbage-collected leaves the server-side query running.TransactionConfig.withTimeout() guarantee that rollback completes before any partial writes are persisted, or can the timeout fire after a partial commit?Result.cancel(), is there a documented transaction lifecycle phase after which cancellation becomes a no-op because the commit has already been acknowledged?34775 reputation · 22 Oct 2024, 19:06 UTC
The core issue lies in the asynchronous nature of the driver-server communication. When a timeout occurs or a cancel is requested, the driver stops waiting for a response and returns an error. However, if the server has already moved to the commit phase, the changes will be persisted despite the driver's reported error.
Application logic cannot reliably differentiate between "rolled back before commit" and "cancelled after commit" using only the driver's exception types. Both paths result in a cancellation-related error because the driver cannot confirm the server-side state once it stops listening for results.
Result.cancel() when you need to stop a query early (e.g., a user closes a UI), but do not rely on it as the primary mechanism for data integrity.Diagnostic Question: Are you using a clustered Neo4j environment or a standalone instance, as propagation lag can affect the visibility of partial writes after a timeout?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.