If I have method with @Transaction
(with default isolation level) and after all it send commit
to DB, DB set transaction’s visible for other and send response back to me, but network is lagging and I receive timeout. What happens? Transaction will be rollbacked?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Based on the Chapter 17. Transaction management of the Spring Framework, in general, if a transaction times out, it will be rolled back.
In the case of using Spring with a Postgresql database, when using the
@Transactional
annotation with a timeout parameter, if the database operation takes longer than the specified timeout period, aTransactionTimedOutException
will be thrown and the transaction will be rolled back .After looking at the comments under the original question, if the database receives the commit but the client does not receive a response due to a network issue, the transaction will still be committed on the database side. The client may receive a timeout error, but the transaction will have been successfully committed on the database
I also recommend this article as it dives deep into how timeouts work.
Typically, when you send a request to the database the transaction is started. During this time, the changes made within the transaction are not visible to other transactions until it is committed or rolled back.
If there is a network issue the transaction may remain in an open state on the database side. It will eventually close the connection due to inactivity or reach a timeout limit. After the connection is closed, the transaction will be automatically rolled back.