lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Chiaretta <simone.chiare...@gmail.com>
Subject Re: Lucene.net in Medium Trust
Date Wed, 05 May 2010 10:06:09 GMT
Hi All,
sorry for taking so long to work on the issue:
Debugging so far, and found out that the problem was not in the open method,
but in the static constructor itself

1 - FSDirectory static constructor:
public static readonly System.String LOCK_DIR =
SupportClass.AppSettings.Get("Lucene.Net.lockDir",
System.IO.Path.GetTempPath());
GetTempPath raises a permission exception when running in medium trust...
since this is even an Obsolete method I just removed the line

2 - Utils.Constants static constructor:
System.Environment.GetEnvironmentVariable: raises an exception medium trust
as well:
The lines with problems are:

   - public static readonly System.String OS_NAME =
   System.Environment.GetEnvironmentVariable("OS") ?? "Linux";
   Just hardcoded "Windows" as I'm not running on other machines... I also
   searched for usages and it's used only in two lines: one in the Directory
   Open method in an if/else statement that does the same things in both trees,
   and the other is in the IndexWriter where the DEFAULT_MAX_SYNC_PAUSE_SECONDS
   is set based on whether it's Windows
   - public static readonly System.String OS_ARCH =
   System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
   Used only as debugging info, so hardcoded it to x86
   - public static readonly System.String OS_VERSION =
   System.Environment.OSVersion.ToString()
   Used only in debugging, hardcoded to String.Empty


With these changes it works even when setting the trust level to medium:
tested adding
<trust level="Medium" originUrl=".*" />
in the config file of the applications

hope this helps
Simo

PS: I also found this blog post that talks about the same problems:
http://www.klopfenstein.net/lorenz.aspx/lucene.net-on-medium-trust-nhibernate-search-part-2
<http://www.klopfenstein.net/lorenz.aspx/lucene.net-on-medium-trust-nhibernate-search-part-2>Too
bad he didn't publish any code, but only released the compiled build file.

On Tue, Feb 16, 2010 at 6:39 PM, digy digy <digydigy@gmail.com> wrote:

> The reason may be the "FlushFileBuffers" in
> "SupportClass.FileSupport.Sync".
> Can you change the code as below and try again?
>
> public static void Sync(System.IO.FileStream fileStream)
> {
>   if (fileStream == null) throw new ArgumentNullException("fileStream");
>   fileStream.Flush();
> }
>
> DIGY
>
> On Tue, Feb 16, 2010 at 6:22 PM, Simone Chiaretta <
> simone.chiaretta@gmail.com> wrote:
>
> > This is the email from the guy that reported the error:
> >
> > It seems like adding the permission to App_Data (where the indexes are
> > located) didn't help.
> >
> > Any ideas?
> > Simone
> >
> > -----------------------------
> >
> > After adding Read/Write/Modify permissions to App_Data for "NETWORK
> > SERVICE" (what the app pool is running under), I got the same
> > permissions issue... but then also got a new one.
> >
> > I added the permissions and did a full IISRESET. I then hit the
> > successfully upgraded site (going to the admin page). The login screen
> > for the admin site came up and I entered my credentials. That's when I
> > got the exception we saw earlier:
> >
> > [SecurityException: Request for the permission of type
> > 'System.Security.Permissions.SecurityPermission, mscorlib,
> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
> > failed.]
> >  FileSupport.Sync(FileStream fileStream) +0
> >  Lucene.Net.Store.FSDirectory.Sync(String name) +151
> >  Lucene.Net.Index.SegmentInfos.FinishCommit(Directory dir) +171
> >  Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > create, Boolean closeDir, IndexDeletionPolicy deletionPolicy, Boolean
> > autoCommit, Int32 maxFieldLength, IndexingChain indexingChain,
> > IndexCommit commit) +257
> >  Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit,
> > Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
> > +110
> >  Lucene.Net.Index.IndexWriter..ctor(Directory d, Analyzer a,
> > MaxFieldLength mfl) +369
> >
> >
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.EnsureIndexWriter()
> > in SearchEngineService.cs:93
> >
> > HOWEVER, if I hit reload, I get a new exception:
> >
> > [LockObtainFailedException: Lock obtain timed out: NativeFSLock@C:\dev
> > \subtext\trunk\src\Subtext.
> > Web\App_Data\write.lock]
> >  Lucene.Net.Store.Lock.Obtain(Int64 lockWaitTimeout) +574
> >    Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > create, Boolean closeDir, IndexDeletionPolicy deletionPolicy, Boolean
> > autoCommit, Int32 maxFieldLength, IndexingChain indexingChain,
> > IndexCommit commit) +154
> >    Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit,
> > Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit commit)
> > +110
> >  Lucene.Net.Index.IndexWriter..ctor(Directory d, Analyzer a,
> > MaxFieldLength mfl) +369
> >
> >
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.EnsureIndexWriter()
> > in SearchEngineService.cs:93
> >
> >
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.DoWriterAction(Func`2
> > action) in SearchEngineService.cs:77
> >
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.get_Searcher()
> > in SearchEngineService.cs:100
> >
> >
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.GetIndexedEntryCount(Int32
> > blogId) in SearchEngineService.cs:159
> >  Subtext.Web.Admin.Pages.HomePageDefault.get_IndexedEntryCount() in
> > C:\dev\subtext\trunk\src\Subtext.Web\aspx\Admin\default.aspx.cs:43
> >
> > Looking in the App_Data folder, there aren't any .lock files. Just
> > the .mdf that comes with the source that I'm not using (I have SQL
> > Server with a backup copy of my real database so I can test).
> >
> > Subsequent reloads yield the lock timeout exception over and over.
> >
> > I tried adding Read/Write/Modify to "EVERYONE" on "App_Data," did
> > IISRESET, and got the same results.
> >
> > ------------
> >
> >
> > On Sat, Feb 13, 2010 at 3:29 AM, Simone Chiaretta <
> > simone.chiaretta@gmail.com> wrote:
> >
> > > Nick, I didn't have time to work on this issue.. I asked to the guy
> that
> > > reported the problem to see if it was a permission problem, but he
> never
> > get
> > > back to me.
> > > But I guess it's not as permission problem as he said that with full
> > trust
> > > it worked
> > >
> > >
> > > On Sat, Feb 13, 2010 at 7:08 AM, Nicholas Paldino [.NET/C# MVP] <
> > > casperOne@caspershouse.com> wrote:
> > >
> > >> Simone,
> > >>
> > >>        Was this ever resolved?  Was it a permissions issue on the
> > App_Data
> > >> folder, or something else?
> > >>
> > >>                - Nick
> > >>
> > >> -----Original Message-----
> > >> From: Simone Chiaretta [mailto:simone.chiaretta@gmail.com]
> > >> Sent: Wednesday, February 10, 2010 6:57 PM
> > >> To: lucene-net-user@lucene.apache.org
> > >> Subject: Re: Lucene.net in Medium Trust
> > >>
> > >> It's the App_Data folder of a web app... it *should* have write access
> > to
> > >> it.
> > >> I'll check it out
> > >> Simo
> > >>
> > >> On Wed, Feb 10, 2010 at 9:12 PM, Digy <digydigy@gmail.com> wrote:
> > >>
> > >> > Hi Simone,
> > >> >
> > >> > Can you try to open/create a file in that directory within your
> > >> app(without
> > >> > using Lucene.NET) to narrow down the source of the problem.
> > >> >
> > >> > DIGY
> > >> >
> > >> > -----Original Message-----
> > >> > From: Simone Chiaretta [mailto:simone.chiaretta@gmail.com]
> > >> > Sent: Wednesday, February 10, 2010 9:46 PM
> > >> > To: lucene-net-user
> > >> > Subject: Lucene.net in Medium Trust
> > >> >
> > >> > Hi all,
> > >> > we are starting to do the final testing with the new release of
> > Subtext
> > >> > which has a Lucene.net based search engine.
> > >> > But we are finding a strange error, related to a SecurityPermission
> > when
> > >> > running in medium trust
> > >> >
> > >> > there is the stack trace of the error:
> > >> >
> > >> > [SecurityException: Request for the permission of type
> > >> > 'System.Security.Permissions.
> > >> > SecurityPermission, mscorlib,
> > >> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
> > >> > failed.]
> > >> >  FileSupport.Sync(FileStream fileStream) +0
> > >> >  Lucene.Net.Store.FSDirectory.Sync(String name) +151
> > >> >  Lucene.Net.Index.SegmentInfos.FinishCommit(Directory dir) +171
> > >> >  Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > >> > create, Boolean closeDir, IndexDeletionPolicy deletionPolicy,
> Boolean
> > >> > autoCommit, Int32 maxFieldLength, IndexingChain indexingChain,
> > >> > IndexCommit commit) +257
> > >> >  Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean
> > >> > closeDir, IndexDeletionPolicy deletionPolicy, Boolean autoCommit,
> > >> > Int32 maxFieldLength, IndexingChain indexingChain, IndexCommit
> commit)
> > >> > +110
> > >> >  Lucene.Net.Index.IndexWriter..ctor(Directory d, Analyzer a,
> > >> > MaxFieldLength mfl) +369
> > >> >
> > >> >
> > >> >
> > >>
> > >>
> >
> Subtext.Framework.Services.SearchEngine.SearchEngineService.EnsureIndexWrite
> > >> > r()
> > >> > in SearchEngineService.cs:93
> > >> >
> > >> > The line of code that causes the error is
> > >> >
> > >> > _writer = new IndexWriter(_directory,
> > >> > _analyzer,IndexWriter.MaxFieldLength.UNLIMITED);
> > >> >
> > >> > where _directory is
> > >> > FSDirectory.Open(new
> > >> > DirectoryInfo(HttpContext.Server.MapPath("~/App_Data"))))
> > >> >
> > >> > We are using one of the latest versions (retrieved from the trunk
> > around
> > >> > the
> > >> > beginning of January) .. 2.9.1 I guess
> > >> >
> > >> > I read you should have fixed the problem in 2.3.2 (
> > >> > http://issues.apache.org/jira/browse/LUCENENET-169) but this
> problem
> > is
> > >> > happening again here.
> > >> >
> > >> > Any idea on what is happening here?
> > >> >
> > >> > Thx
> > >> > 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"
> > >> >
> > >> >
> > >>
> > >>
> > >> --
> > >> 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"
> > >>
> > >
> > >
> > >
> > > --
> > > 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"
> > >
> >
> >
> >
> > --
> > 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"
> >
>



-- 
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