lucene-lucene-net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Chiaretta <simone.chiare...@gmail.com>
Subject "Lock obtain timed out: SimpleFSLock" appearing sometimes
Date Mon, 04 Jan 2010 21:16:44 GMT
Hi all,
since it's my first time here I'd like to introduce myself.
My name is Simone Chiaretta, and I'm member of Subtext blogging engine team,
and I'm a ASP.NET MVC fan.
I also have a blog at http://codeclimber.net.nz, where I also wrote a few
posts about Lucene.net

But going back to the main topic of this email: I'm implementing a
Lucene.net based search engine for Subtext and I'm writing because I've a
strange problem that happens from times to times:
I get the exception of the subject "Lock obtain timed out: SimpleFSLock..."
every now and then when the ApplicationPool recycles.

I know only one IndexWriter can exist at a time, and in fact the writer is a
static variable inside the search engine service.

The problem seems that the Dispose of the search engine, which closes the
writer is not enough for releasing the lock.

        public void Dispose()
        {
            var searcher = _searcher;
            if (searcher != null)
            {
                searcher.Close();
            }

            var writer = _writer;
            if (writer != null)
            {
                writer.Close();
            }

            var directory = _directory;
            if(directory != null) {
              directory.Close();
            }

            writer = _writer;
            if (writer != null)
            {
                _writer = null;
            }
        }

For the moment I made 2 workaround that I hope will solve the problem:

I'm checking weather the index is locked or not before creating a new one

if(_writer==null)
{
    if(IndexReader.IsLocked(_directory))
    {
        __log.Error("Something left a lock in the index folder: deleting
it");
        IndexReader.Unlock(_directory);
        __log.Info("Lock Deleted... can proceed");
    }
    _writer = new IndexWriter(_directory, _analyzer);
    _writer.Optimize();
}

and I'm explicitly disposing the search engine in the Application_End event
of the WebApplication

searchEngine.Dispose();

But I'd like to know if maybe I'm making some mistake somewhere that is
causing the problem, or if there is a more elegant way to fix this problem.

For a complete reference here is the link to the latest version of the
SearchEngineService class that encapsulate all the fulltext searching logic
of Subtext
http://code.google.com/p/subtext/source/browse/trunk/src/Subtext.Framework/Services/SearchEngine/SearchEngineService.cs

Oh... one last thing.. I'm using Lucene.net 2.3.2

Thank you
Simone


-- 
Simone Chiaretta
Microsoft MVP ASP.NET - ASPInsider
Blog: http://codeclimber.net.nz
RSS: http://feeds2.feedburner.com/codeclimber
twitter: @simonech

Any sufficiently advanced technology is indistinguishable from magic
"Life is short, play hard"

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