BUG: Lucene.Net.Store.NativeFSLockFactory: Missing lock on dictionary when 
NativeFSLock.Dispose() is called. Also, the lock needs to be removed from the 
cache whether it has opened a file or not.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/2bfa241d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/2bfa241d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/2bfa241d

Branch: refs/heads/master
Commit: 2bfa241d8913cf956d5fd28e0c374282f3363d07
Parents: 4fdf672
Author: Shad Storhaug <[email protected]>
Authored: Fri Sep 15 09:01:13 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Fri Sep 15 09:01:13 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net/Store/NativeFSLockFactory.cs | 43 ++++++++++++++----------
 1 file changed, 26 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2bfa241d/src/Lucene.Net/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs 
b/src/Lucene.Net/Store/NativeFSLockFactory.cs
index 8157e13..ca2a158 100644
--- a/src/Lucene.Net/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs
@@ -273,27 +273,36 @@ namespace Lucene.Net.Store
             {
                 lock (this)
                 {
-                    if (channel != null)
+                    // whether or not we have created a file, we need to remove
+                    // the lock instance from the dictionary that tracks them.
+                    try
                     {
-                        try
-                        {
+                        lock (NativeFSLockFactory._locks)
                             NativeFSLockFactory._locks.Remove(path);
-                        }
-                        finally
+                    }
+                    finally
+                    {
+                        if (channel != null)
                         {
-                            IOUtils.DisposeWhileHandlingException(channel);
-                            channel = null;
-                        }
+                            try
+                            {
+                                IOUtils.DisposeWhileHandlingException(channel);
+                            }
+                            finally
+                            {
+                                channel = null;
+                            }
 #if FEATURE_FILESTREAM_LOCK
-                        // try to delete the file if we created it, but it's 
not an error if we can't.
-                        try
-                        {
-                            File.Delete(path);
-                        }
-                        catch
-                        {
-                        }
+                            // try to delete the file if we created it, but 
it's not an error if we can't.
+                            try
+                            {
+                                File.Delete(path);
+                            }
+                            catch
+                            {
+                            }
 #endif
+                        }
                     }
                 }
             }
@@ -339,4 +348,4 @@ namespace Lucene.Net.Store
             return "NativeFSLock@" + path;
         }
     }
-}
+}
\ No newline at end of file

Reply via email to