dotCMS / core

Headless/Hybrid Content Management System for Enterprises
http://dotcms.com
Other
864 stars 467 forks source link

IndexOutOfBoundsException in sitesearch portlet #28779

Closed waqasakramdot closed 3 months ago

waqasakramdot commented 5 months ago

Parent Issue

No response

Problem Statement

A customer reported an issue related to sitesearch and in the logs shows.


40: 
41: 
42: 
43: List<String> indices=ssapi.listIndices();
44: List<String> closedIndices=ssapi.listClosedIndices();
45: 
46: Map<String, IndexStats> indexInfo = esapi.getIndicesStats();

Stacktrace:
org.apache.jasper.JasperException: An exception occurred processing [/html/portlet/ext/sitesearch/site_search_index_stats.jsp] at line [43]

40: 
41: 
42: 
43: List<String> indices=ssapi.listIndices();
44: List<String> closedIndices=ssapi.listClosedIndices();
45: 
46: Map<String, IndexStats> indexInfo = esapi.getIndicesStats();

Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610) ~[jasper.jar:9.0.60]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499) ~[jasper.jar:9.0.60]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379) ~[jasper.jar:9.0.60]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327) ~[jasper.jar:9.0.60]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[servlet-api.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-websocket.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotmarketing.filters.CMSFilter.doFilterInternal(CMSFilter.java:181) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at com.dotmarketing.filters.CMSFilter.doFilter(CMSFilter.java:61) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.filters.interceptor.AbstractWebInterceptorSupportFilter.doFilter(AbstractWebInterceptorSupportFilter.java:90) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.filters.interceptor.AbstractWebInterceptorSupportFilter.doFilter(AbstractWebInterceptorSupportFilter.java:90) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.visitor.filter.servlet.VisitorFilter.doFilter(VisitorFilter.java:81) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.vanityurl.filters.VanityURLFilter.doFilter(VanityURLFilter.java:114) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) ~[urlrewritefilter-4.0.4.jar:4.0.4]
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) ~[urlrewritefilter-4.0.4.jar:4.0.4]
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) ~[urlrewritefilter-4.0.4.jar:4.0.4]
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389) ~[urlrewritefilter-4.0.4.jar:4.0.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotmarketing.filters.TimeMachineFilter.doFilter(TimeMachineFilter.java:137) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotmarketing.filters.ThreadNameFilter.doFilter(ThreadNameFilter.java:88) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotmarketing.filters.CookiesFilter.doFilter(CookiesFilter.java:53) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotmarketing.filters.CharsetEncodingFilter.doFilter(CharsetEncodingFilter.java:99) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.filters.interceptor.AbstractWebInterceptorSupportFilter.doFilter(AbstractWebInterceptorSupportFilter.java:90) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:126) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at com.dotcms.filters.NormalizationFilter.doFilter(NormalizationFilter.java:89) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[catalina.jar:9.0.60]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[catalina.jar:9.0.60]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687) ~[catalina.jar:9.0.60]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[catalina.jar:9.0.60]
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:769) ~[catalina.jar:9.0.60]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[catalina.jar:9.0.60]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) ~[catalina.jar:9.0.60]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) ~[tomcat-coyote.jar:9.0.60]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-coyote.jar:9.0.60]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889) ~[tomcat-coyote.jar:9.0.60]
at org.apache.tomcat.util.net.Nio2Endpoint$SocketProcessor.doRun(Nio2Endpoint.java:1701) ~[tomcat-coyote.jar:9.0.60]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-coyote.jar:9.0.60]
at org.apache.tomcat.util.net.AbstractEndpoint.processSocket(AbstractEndpoint.java:1190) ~[tomcat-coyote.jar:9.0.60]
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$2.completed(Nio2Endpoint.java:633) ~[tomcat-coyote.jar:9.0.60]
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$2.completed(Nio2Endpoint.java:611) ~[tomcat-coyote.jar:9.0.60]
at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127) ~[?:?]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishRead(UnixAsynchronousSocketChannelImpl.java:439) ~[?:?]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:191) ~[?:?]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213) ~[?:?]
at sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:306) ~[?:?]
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 3
at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) ~[?:?]
at java.util.Objects.checkIndex(Objects.java:372) ~[?:?]
at java.util.ArrayList.remove(ArrayList.java:536) ~[?:?]
at com.dotcms.enterprise.publishing.sitesearch.ESSiteSearchAPI.setDefaultToSpecificPosition(ESSiteSearchAPI.java:168) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at com.dotcms.enterprise.publishing.sitesearch.ESSiteSearchAPI.listIndices(ESSiteSearchAPI.java:150) ~[dotcms_23.10.24_lts_v2_5374aed.jar:?]
at org.apache.jsp.html.portlet.ext.sitesearch.site_005fsearch_005findex_005fstats_jsp._jspService(site_005fsearch_005findex_005fstats_jsp.java:553) ~[?:?]
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) ~[jasper.jar:9.0.60]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[servlet-api.jar:4.0.FR]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466) ~[jasper.jar:9.0.60]
... 77 more

Steps to Reproduce

  1. Create a few SS indices
  2. Set one as default
  3. Delete the default SS index directly from ES:
    curl -X DELETE "http://localhost:9200/{index_name}"
  4. Flush Cache
  5. Try to create a new SS index

This line throws an error
https://github.com/dotCMS/core/blob/8b71ba0ef58e824ad5e63645e65c1285bcaa6847/dotCMS/src/enterprise/java/com/dotcms/enterprise/publishing/sitesearch/ESSiteSearchAPI.java#L163

Because list.indexOf(defaultIndice); returns -1 if default indices are not there in the list

final int index = list.indexOf(defaultIndice);
                    //change the element defaultIndex to the first position of the arraylist if it is not yet
                    if (index != 0) {
                        list.remove(index);
                        list.add(indexPosition, defaultIndice);
                    }

The root cause is here. indiciesAPI.loadIndicies() returns different results https://github.com/dotCMS/core/blob/8b71ba0ef58e824ad5e63645e65c1285bcaa6847/dotCMS/src/enterprise/java/com/dotcms/enterprise/publishing/sitesearch/ESSiteSearchAPI.java#L161

Acceptance Criteria

The logic error should handle and indexoutofbound should never return if difference in indeces

dotCMS Version

24.*

Proposed Objective

Customer Support

Proposed Priority

Priority 4 - Trivial

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

https://dotcms.zendesk.com/agent/tickets/116403

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

erickgonzalez commented 5 months ago

Another Customer hitting this: https://dotcms.zendesk.com/agent/tickets/116552

Workaround

It was to remove the default SS index directly from the DB and flush the cache. Afterwards, the portlet started to show up, and we were able to set up the SS index default again.

erickgonzalez commented 3 months ago

I've observed this issue with customers a few times; the most common cause is the non-existence of the Default index. Let's implement validation for this and also add a WARN log when the Default index isn't present.

bryanboza commented 3 months ago

Fixed, this is working as expected, no error after delete the index

Tested on [ trunk_78bb755 ] // Docker

erickgonzalez commented 2 months ago

This does not apply to 23.01 LTS since the code doesn't exist.