OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.45k stars 2.41k forks source link

Lucene.Net.QueryParsers.Classic.ParseException #16373

Closed mohit-naroliya closed 3 months ago

mohit-naroliya commented 5 months ago

Describe the bug

We encountered a strange issue on the production site that caused it to go down. After investigating, we found few exceptions in the log related to Lucene. Here are the logged exceptions:

OrchardCore.Search.Lucene.Services.LuceneSearchService|ERROR|Incorrect Lucene search query syntax provided in search. Lucene.Net.QueryParsers.Classic.ParseException: Cannot parse '"Find Your New Water Billing Account and Customer IDs': Lexical error at line 1, column 54.  Encountered: <EOF> after : "\"Find Your New Water Billing Account and Customer IDs"
---> Lucene.Net.QueryParsers.Classic.TokenMgrError: Lexical error at line 1, column 54.  Encountered: <EOF> after : "\"Find Your New Water Billing Account and Customer IDs"
   at Lucene.Net.QueryParsers.Classic.QueryParserTokenManager.GetNextToken()
   at Lucene.Net.QueryParsers.Classic.QueryParser.Jj_ntk()
   at Lucene.Net.QueryParsers.Classic.QueryParser.Modifiers()
   at Lucene.Net.QueryParsers.Classic.QueryParser.Query(String field)
   at Lucene.Net.QueryParsers.Classic.QueryParserBase.Parse(String query)
   --- End of inner exception stack trace ---
   at Lucene.Net.QueryParsers.Classic.QueryParserBase.Parse(String query)
   at OrchardCore.Search.Lucene.Services.LuceneSearchService.SearchAsync(String indexName, String term, Int32 start, Int32 size)    at Lucene.Net.QueryParsers.Classic.QueryParserBase.Parse(String query)
   at OrchardCore.Search.Lucene.Services.LuceneSearchService.SearchAsync(String indexName, String term, Int32 start, Int32 size)

Following the initial exception, we started receiving numerous connection failed exceptions, which ultimately caused the site to go down. Here is the log and the relevant exceptions:

Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer|ERROR|Connection ID "16933534604013338735", Request ID "4000007b-0001-eb00-b63f-84710c7967bb": An unhandled exception was thrown by the application. System.InvalidOperationException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
   at Microsoft.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location ---
   at OrchardCore.Queries.Sql.SqlQuerySource.ExecuteQueryAsync(Query query, IDictionary`2 parameters)
   at OrchardCore.Queries.Sql.SqlQuerySource.ExecuteQueryAsync(Query query, IDictionary`2 parameters)
   at OrchardCore.Queries.Liquid.QueryFilter.ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
   at Fluid.Ast.FilterExpression.EvaluateAsync(TemplateContext context)
   at Fluid.Ast.AssignStatement.<WriteToAsync>g__Awaited|7_0(ValueTask`1 task, TemplateContext context, String identifier)
   at Fluid.Parser.FluidTemplate.Awaited(ValueTask`1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList`1 statements, Int32 startIndex)
   at OrchardCore.DisplayManagement.Liquid.LiquidViewTemplateExtensions.RenderAsync(LiquidViewTemplate template, TextWriter writer, TextEncoder encoder, LiquidTemplateContext context, Object model)
   at OrchardCore.Liquid.Services.LiquidTemplateManager.RenderHtmlContentAsync(String source, TextEncoder encoder, Object model, IEnumerable`1 properties)
   at OrchardCore.Templates.Services.TemplatesShapeBindingResolver.<>c__DisplayClass8_0.<<BuildShapeBinding>b__0>d.MoveNext()

I went through the OC branch code base and found that there is a method opening a SQL Server connection without properly closing it. This could be the reason we are reaching the maximum connection pool size, leading to the site going down.

image

Above image method calling from the IndexingBackgroundTask that runs every minute.

Orchard Core version - 1.8.3

github-actions[bot] commented 5 months ago

Thank you for submitting your first issue, awesome! 🚀 We're thrilled to receive your input. If you haven't completed the template yet, please take a moment to do so. This ensures that we fully understand your feature request or bug report. A core team member will review your issue and get back to you.

If you like Orchard Core, please star our repo and join our community channels.

sebastienros commented 5 months ago

How is the Lucene query issue related to the SQL connections pool limits? Can you share more of the stack-trace where the lucene issue is coming from? I want to understand what is sending user input as a lucene query. Because what is happening is that the code is expecting a lucene query, but the user doesn't provide that. There is a mismatch that needs to be resolved. If it's your code then don't expect a query from the user, build a query from the text that is provided. IF it's OC's code we need to fix it, but we need to know what is calling it.

The example you showed for the connection is actually closing it as it's using a using statement that will dispose and close the connection however it exits the method. It doesn't mean there is no such issue, but not in the code you pointed to.

github-actions[bot] commented 4 months ago

It seems that this issue didn't really move for quite a while despite us asking the author for further feedback. Is this something you'd like to revisit any time soon or should we close? Please reply.

github-actions[bot] commented 4 months ago

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

github-actions[bot] commented 4 months ago

It seems that this issue didn't really move for quite a while despite us asking the author for further feedback. Is this something you'd like to revisit any time soon or should we close? Please reply.

github-actions[bot] commented 3 months ago

Closing this issue because it didn't receive further feedback from the author for very long. If you think this is still relevant, feel free to reopen it with the requested details.