New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent corrupted ThreadLocals when mis-using triggerAfterCommit [SPR-11761] #16383
Comments
Stéphane Nicoll commented See repro project: https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-11761 |
Stéphane Nicoll commented Removing the I haven't got what is going on but in the after completion hook you make sure that you can't use a transaction and then right after you invoke a method with requires new. I am a bit confused as why you're doing that.
That's not what the test shows as Book 4 ( |
Aldrin Seychell commented Attaching patch file with a our "proposed" fix for this bug. |
Aldrin Seychell commented The method is annotated with In the unit test, Book 4 is only found when a lookup is performed in the same thread. When the lookup is carried out in the a separate thread The biggest issues we see here is that after this specific sequence of events, anything that is processed on this particular thread will not be persisted to the database. We believe that this process can be failed if it is not executing as it should but other independent processes on the same thread should not fail or end up with missing data. |
Stéphane Nicoll commented I read the test backwards. This is more clear now, thanks. I guess the main problem is that you're playing with transactions in the transaction callback, which you are not suppose to do by the way (
The problem is that your code calls a method that does impact the current thread because you mark the thread as not supporting transaction all the sudden. I'll do some homework to see if what you're experiencing can happen in a "regular" case but if not I would ask you to isolate your transactional operation there in a transaction with |
Aldrin Seychell commented We are now aware that we misused the transactions synchronisation callback. In fact, we fixed this issue in our code by not misusing it in this way. However, we believe that the transactions state maintained by Spring should not be corrupted by such a misuse and in fact there was no indication in the server logs that there was a misuse and the state got corrupted. This made the symptom of disappearing data difficult to track down to this particular scenario. We believe that the Spring framework should protect its state from becoming corrupted as a result of an API misuse. The attached patch (which we already applied to our copy of the spring libraries) prevents that the Spring's state from becoming corrupt. All our tests using this patch were successful which gave us peace of mind to push this patch to our production systems. |
Aldrin Seychell commented I just tested this issue with 4.3.15 and it seems to have been fixed. Thanks! |
Juergen Hoeller commented Indeed, this seems to be covered by #16214 as of 4.3.7. Good to hear! |
Aldrin Seychell opened SPR-11761 and commented
This issue started when we noticed a number of missing data in our database and not matching our reports, all resulting from a particular thread. This problem was being triggered after utilizing the
TransactionSynchronizationManager.registerSynchronization
method and implementing theafterCompletion
method to trigger a separate transaction to perform some further logic afterwards. However, when calling a method annotated with a@Transactional(propagation=NEVER)
, this seems to be corrupting the threadLocal variables and the transactional resources being tied to thread indefinitely. Any subsequent calls from this thread to persist new data will never reach the database but will never fail.Affects: 3.1.1, 4.0.4
Reference URL: spring-attic/spring-framework-issues#74
Attachments:
Issue Links:
Referenced from: commits spring-attic/spring-framework-issues@8945dd9, spring-attic/spring-framework-issues@41578e8
1 votes, 4 watchers
The text was updated successfully, but these errors were encountered: