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

NRTCachingDirectory doesn't allow double dispose calls #841

Closed
NightOwl888 opened this issue Apr 23, 2023 · 0 comments · Fixed by #854
Closed

NRTCachingDirectory doesn't allow double dispose calls #841

NightOwl888 opened this issue Apr 23, 2023 · 0 comments · Fixed by #854
Assignees
Labels
design is:bug is:enhancement New feature or request pri:high up-for-grabs This issue is open to be worked on by anyone

Comments

@NightOwl888
Copy link
Contributor

NightOwl888 commented Apr 23, 2023

Per the dispose pattern docs:

✓ DO allow the Dispose(bool) method to be called more than once. The method might choose to do nothing after the first call.

X AVOID throwing an exception from within Dispose(bool) except under critical situations where the containing process has been corrupted (leaks, inconsistent shared state, etc.).

NRTCachingDirectory violates both of these rules by throwing an ObjectDisposedException the second time Dispose() is called. We need to be careful about how to fix this and ensure the usage pattern will work after the fix has been applied.

System.ObjectDisposedException : this Directory is disposed.
Object name: 'Lucene.Net.Store.RAMDirectory'.

To reproduce this test result:

Option 1:

Apply the following assembly-level attributes:

[assembly: Lucene.Net.Util.RandomSeed("0xc6267c4598373666")]
[assembly: NUnit.Framework.SetCulture("gd")]

Option 2:

Use the following .runsettings file:

<RunSettings>
<TestRunParameters>
<Parameter name="tests:seed" value="0xc6267c4598373666" />
<Parameter name="tests:culture" value="gd" />
</TestRunParameters>
</RunSettings>

See the .runsettings documentation at: https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file.
at Lucene.Net.Store.BaseDirectory.EnsureOpen() in /_/src/Lucene.Net/Store/BaseDirectory.cs:line 77
at Lucene.Net.Store.RAMDirectory.ListAll() in /_/src/Lucene.Net/Store/RAMDirectory.cs:line 123
at Lucene.Net.Store.NRTCachingDirectory.Dispose(Boolean disposing) in /_/src/Lucene.Net/Store/NRTCachingDirectory.cs:line 362
at Lucene.Net.Store.MockDirectoryWrapper.Dispose(Boolean disposing) in /_/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs:line 1108
at Lucene.Net.Store.Directory.Dispose() in /_/src/Lucene.Net/Store/Directory.cs:line 134
at Lucene.Net.Index.TestIndexWriterOnJRECrash.CheckIndexes(FileSystemInfo file) in /_/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs:line 324
at Lucene.Net.Index.TestIndexWriterOnJRECrash.TestNRTThreads_Mem() in /_/src/Lucene.Net.Tests/Index/TestIndexWriterOnJRECrash.cs:line 87
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

@NightOwl888 NightOwl888 added up-for-grabs This issue is open to be worked on by anyone is:bug design is:enhancement New feature or request pri:high labels Apr 23, 2023
@NightOwl888 NightOwl888 self-assigned this May 13, 2023
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue May 14, 2023
…n Dispose() is called multiple times. Also added checks to ensure an ObjectDisposedException is thrown by any method call after Dispose() is called. Fixed all other directory implementations and made the check atomic so only the first call to Dispose() is run. Fixes apache#841. Related to apache#265.
NightOwl888 added a commit that referenced this issue May 16, 2023
…n Dispose() is called multiple times. Also added checks to ensure an ObjectDisposedException is thrown by any method call after Dispose() is called. Fixed all other directory implementations and made the check atomic so only the first call to Dispose() is run. Fixes #841. Related to #265.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design is:bug is:enhancement New feature or request pri:high up-for-grabs This issue is open to be worked on by anyone
Projects
None yet
1 participant