Skip to content
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

Fixes Lucene.Net.Index.TestIndexWriter::TestThreadInterruptDeadlock() and Lucene.Net.Index.TestIndexWriter::TestTwoThreadsInterruptDeadlock() #525

Merged
merged 8 commits into from
Oct 17, 2021

Conversation

NightOwl888
Copy link
Contributor

This fixes Lucene.Net.Index.TestIndexWriter::TestThreadInterruptDeadlock() and Lucene.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 all lock statements in the solution with a new UninterruptableMonitor class. This class handles the exceptions that .NET throws and, if they occur, resets Thread.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.

…extra Thread.Sleep(0) call in IndexWriter.Dispose().
… handle entering locks without throwing System.Threading.ThreadInterruptedException (which is what happens in Java)
…tor.Enter and UninterruptableMonitor.Exit to prevent ThreadInterruptedException from occurring when entering a lock.
…erruptableMonitor.Enter and UninterruptableMonitor.Exit to prevent ThreadInterruptedException from occurring when entering a lock.
…d UninterruptableMonitor.Exit to prevent ThreadInterruptedException from occurring when entering a lock.
… from TestThreadInterruptDeadlock() and TestTwoThreadsInterruptDeadlock(), since they now are passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant