0
votes

I'm using open LDAP running on one server and it is running on 10.0.26.X IP and my client is running on IP 10.0.25.X and firewall in between but port 389 is open and in listen state. So problem I'm facing issue with the client is that it closes the client server and after that I have to restart the client in every 6 hours then it works fine for sometime then again giving same issue.

I have tried to open connection between my client and open LDAP but same issue. Also from the firewall end we have tried everything.

Hashtable<String, String> envMap = new Hashtable<>();
    envMap.put(Context.INITIAL_CONTEXT_FACTORY, initContextFactory);
    envMap.put(Context.PROVIDER_URL, providerUrl);
    envMap.put(Context.SECURITY_AUTHENTICATION, securityAuthentication);
    envMap.put(Context.SECURITY_PRINCIPAL, userDN);
    envMap.put(Context.SECURITY_CREDENTIALS, password);
    DirContext userCtx = new InitialDirContext(envMap);

SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String filter = MessageFormat.format(Constants.LDAP_PERSON_FILTER, attrKey, attrValue);
        NamingEnumeration<SearchResult> userResults = dirReaderctx.search(Constants.LDAP_DOMAIN_NAME,
                filter, controls);
        if (userResults.hasMore()) {
            searchResult = userResults.next();
            return searchResult;
        }

Exception I'm getting is :

[com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:2002), com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1844), com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769), com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392), com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358), com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:341), javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267), sun.reflect.GeneratedMethodAccessor100.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43), java.lang.reflect.Method.invoke(Method.java:498), org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209), org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136), org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102), org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877), org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783), org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdater.handle(AbstractHandlerMethodAdapter.java:87), org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991), org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925), org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974), org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877), javax.servlet.http.HttpServlet.service(HttpServlet.java:661), org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851), javax.servlet.http.HttpServlet.service(HttpServlet.java:742), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166), org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166), org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90), org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107), org.apache.catalina.core.ApplicationFilterChain.inernalDoFilter(ApplicationFilterChain.java:193), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166), org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166), org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99), org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193),org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96), org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493), org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140), org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81), org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87), org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342), org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800), org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66),org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800), org.apache.tomcat.utit.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471), org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49), java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149), java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624), org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61), java.lang.Thread.run(Thread.java:748)]

2
That is not an exception, that is a call stack (not a stacktrace). What is the exception?Andreas
Only this I'm getting from the logs.Abhinav Morghade
I find that hard to believe, but if true, then you should fix the bad logging code.Andreas
I will print full exception then it will be more helpfull but is there anything wrong with the ldap connection? because my server is down after same trace 2,3 times then server is in hanging mode I have to restart again then it is working.Abhinav Morghade

2 Answers

0
votes

Not knowing the exception, one thing that is wrong, is that you're not calling the close() method on the NamingEnumeration, so you're leaking resources.

If it works for a while, then stops working, that is very likely a resource-exhaustion exception you're getting.

NamingEnumeration<SearchResult> userResults = dirReaderctx.search(Constants.LDAP_DOMAIN_NAME,
        filter, controls);
if (userResults.hasMore()) {
    searchResult = userResults.next();
    userResults.close(); // <-- add this line
    return searchResult;
}
0
votes

After debugging into many things got answer of this question. As I'm creating a connection only once throughout a application. It is working on the same subnet on IP because there is no firewall in between. But when it is moved to different subnet this error comes in picture due to the connection closure because firewall closes a connection which stands for longer time. To resolve this I am creating a connection request whenever it is required and pooling that same connection so if next request comes if the connection is available into the connection pool then the same is being used otherwise new connection is created and closing the same after doing work. :)