chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 66 forks source link

Second session.Commit() call doesn't close an preview IndexReader inside IndexSearcher #70

Closed igor739 closed 10 years ago

igor739 commented 10 years ago

Hi.

When i execute this code

 var provider = ...
 using (var session = ..)
 {
            session.Add(..);

            session.Commit();
            session.Add(...)
 }

 provider.Dispose();

and having application opened

I can't remove or move my created index files from disk because they are used by a process.

Examining the code i found that the context.Reload() call recreates IndexSearcher with a new IndexReader instance, but the old reader remains still opened inside the tracker's IndexSearcher. And tracker.Dispose() just disposes the IndexSearcher that was created with an internal closeReader: false flag so it remains opened.

From lucene sources it's clear

/// Note that the underlying IndexReader is not closed, if /// IndexSearcher was constructed with IndexSearcher(IndexReader r). /// If the IndexReader was supplied implicitly by specifying a directory, then /// the IndexReader gets closed. /// ///

public IndexSearcher(IndexReader r):this(r, false) { }

Maybe this was a strategy. I am asking because this issue doesn't give me a chanse to optimize the index because it's remains opened.

Thanks

chriseldredge commented 10 years ago

Confirmed bug. Disposing LuceneDataProvider should release the index but does not.

chriseldredge commented 10 years ago

Fixed in e7126dc42cdd08cb886621f33d4e9cb1aa364b88. Thanks for reporting the problem and locating the cause.