Cannot detect transaction timeout after query execution on DataSourceTransactionManager [SPR-14038] #18610
Currently, there are cases where the transaction in excess of the timeout period is committed.
This behavior is same with
I hope to detect timeout at committing. What do you think ?
The text was updated successfully, but these errors were encountered:
Juergen Hoeller commented
This is unfortunately a fundamental limitation of timeout handling against native resources: They all just support timeout hints but no timeout enforcement. As a consequence, a Spring-specified timeout is also just a hint: It may lead to an enforced timeout depending on the transaction manager (like in the JTA case where a parallel cleanup thread cancels timed-out transactions) but usually just suggests a timeout to the underlying resource. This is similar to a Spring-specified read-only flag which is also just an optimization hint, not a hard enforcement.
We could theoretically cancel a transaction at commit time if we determine that it took too long. However, that seems wasteful: The operations did succeed by then, and with a native transaction manager, the subsequent commit signal is usually a quick step to take. Enforcing a timeout at that late point, for a transaction which essentially has been successful, seems counter-intuitive. After all, timeouts are primarily there to avoid hanging when an operation runs into a lock, not for a hard cancel attempt when an operation happened to take slightly longer than expected.
Kazuki Shimizu commented
Juergen Hoeller, thanks for answer !!!
However, in my application, it want to ensure rollback a transaction, if read-timeout was detected at Client application.
My team was consider a following solution:
If can ensure to rollback transaction when transaction timeout was occurred, we thought this issue can be resolved by timeout desgin except for the rare case.
Have best practice to implements this specification on spring application(actually, spring boot application) ?