lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allan, Brad (Bracknell)" <Brad.Al...@Fiserv.com>
Subject IndexReader disposal causing unexpected 'AlreadyClosedException'
Date Mon, 24 Mar 2014 15:55:03 GMT
I've create some pseudo code to try and describe what I'm seeing. This 'problem' can also be
replicated without multiple threads (sessions as I describe them below) if the order of operations
is as described below.

How am I misunderstanding the Lucene docs (around Reopen() method)?
I have looked into the source code and the Dispose does appear to not want to close the reader
if there are existing refs. What do I need to do in my code to ensure the following scenario
does not occur?

A solution I'm mulling over is to keep an additional reference count for the readers I dish
out from 'MyCache' and only Dispose the reader when MyCache knows there are no existing refs
to the 'old' reader.

Wise words appreciated. Thanks.

// Session 1
var reader1 = GetIndexReaderFromMyCache("MyTestIndex");

// Session 2
....some changes are made to 'MyTestIndex'.....

// Session 3
var reader3 = GetIndexReaderFromMyCache("MyTestIndex");

// Session 1
....perform a search with reader1....
BOOM! get 'AlreadyClosedException'

Where:
-----------
IndexReader GetIndexReaderFromMyCache(string indexName) {
     lock(lockObject) {
           IndexReader reader = MyCache.Get(indexName);
           IndexReader newReader = reader.Reopen();
           if (newReader != reader) {
                reader.Dispose();
           }
           reader = newReader;
           MyCache.Update(indexName, reader);
           return reader;
     }
}


________________________________

CheckFree Solutions Limited (trading as Fiserv)
Registered Office: Eversheds House, 70 Great Bridgewater Street, Manchester, M15 ES
Registered in England: No. 2694333

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message