Fixes Lucene.Net.Index.TestIndexWriter::TestThreadInterruptDeadlock() and Lucene.Net.Index.TestIndexWriter::TestTwoThreadsInterruptDeadlock() #525
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes
Lucene.Net.Index.TestIndexWriter::TestThreadInterruptDeadlock()
andLucene.Net.Index.TestIndexWriter::TestTwoThreadsInterruptDeadlock()
as well as sporadic deadlocks we were getting when doing a complete test run.The issue is that .NET considers any wait state (including waiting on a lock) to be a valid condition for throwing a
System.Threading.ThreadInterruptedException
. This makes it difficult to deal with this exception because it is not necessarily thrown when the application is in a known consistent state. The workaround was to replace alllock
statements in the solution with a newUninterruptableMonitor
class. This class handles the exceptions that .NET throws and, if they occur, resetsThread.CurrentThread.Interrupt()
to put the thread back into the same state it was at the beginning of the method. This is not a complete solution, though, because we may interrupt on code that we don't own such as one of the dependencies or user injected code (such as a custom Directory implementation). A more complete solution will be needed for the release, but this is still a big improvement over the last release.This PR also includes the changes from #511 and thus supersedes it.
In addition, we have removed the
[Deadlock]
attribute from several tests and the[AwaitsFix]
attribute from the tests in the title.