<< Back to previous view

[GLASSFISH-15447] External resource permamenly fails on connection error Created: 05/Jan/11  Updated: 19/Feb/13  Resolved: 19/Feb/13

Status: Closed
Project: glassfish
Component/s: jca
Affects Version/s: None
Fix Version/s: 4.0

Type: Bug Priority: Major
Reporter: rsmogura Assignee: naman_mehta
Resolution: Fixed Votes: 4
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Build 35


File Attachments: Text File JndiProxyObjectFactory.java.diff    
Tags: 3_1-exclude 3_1-next 3_1_1-scrubbed 3_1_2-exclude
Participants: c_krebs, Cheng Fang, naman_mehta, rsmogura, scatari and t_tretau

 Description   

When connection to external LDAP will be closed in any reason, then only server restart allows to reconnect to it.
Index: JndiProxyObjectFactory.java
— JndiProxyObjectFactory.java Base (BASE)
+++ JndiProxyObjectFactory.java Locally Modified (Based On LOCAL)
@@ -46,6 +46,7 @@

import java.util.Enumeration;
import java.util.Hashtable;
+import javax.naming.CommunicationException;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
@@ -60,7 +61,6 @@

  • A proxy object factory for an external JNDI factory
    */
    public class JndiProxyObjectFactory implements ObjectFactory {
    -
    // for every external-jndi-resource there is an InitialContext
    // created from the factory and environment properties
    private static Hashtable<ResourceInfo, Context> contextMap = new Hashtable<ResourceInfo, Context>();
    @@ -161,7 +161,24 @@

// use the name to lookup in the external JNDI naming context
try {
+ try { return context.lookup(jndiLookupName); + }catch(CommunicationException ce) {
+ //Silently skip, we can show warning here
+ synchronized(contextMap) {
+ Object result;
+ try { + //On "stack" can be old context + context = contextMap.get(resourceInfo); + result = context.lookup(jndiLookupName); + }catch(CommunicationException recreateContext) { + context = loadInitialContext(jndiFactoryClass, env); + result = context.lookup(jndiLookupName); + contextMap.put(resourceInfo, context); + return result; + }
+ }
+ }
} catch (NameNotFoundException e) { throw new ExternalNameNotFoundException(e); }



 Comments   
Comment by rsmogura [ 13/Jan/11 11:27 PM ]

This is bettered version

Comment by scatari [ 07/Jun/11 02:12 PM ]

To be considered for the next release, but this is not a common use case.

Comment by Cheng Fang [ 13/Jun/11 11:57 AM ]

assign to connector team for evaluation.

Comment by t_tretau [ 24/Oct/11 10:15 AM ]

Looks like this is the same problem. I use an external jndi resource and after some time the connection hangs. Only restart works..

[#|2011-10-24T11:05:44.091+0200|SEVERE|glassfish3.1.1|com.xxx.spnego.IntranetSpnegoServerAuthModule|_ThreadID=22;_ThreadName=Thread-2;|Error accessing ldap directory.
javax.naming.NamingException: Lookup failed for 'ADLDAP' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.s un.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.CommunicationException: Connection reset [Root exception is java.n
et.SocketException: Connection reset]; remaining name 'DC=hsdg-ad,DC=int']
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.xxx.spnego.IntranetSpnegoServerAuthModule.getGroupsForCaller(IntranetSpnegoServerAuthModule.java:46)
at net.java.spnego.SpnegoServerAuthModule.setCallerPrincipal(SpnegoServerAuthModule.java:458)
at net.java.spnego.SpnegoServerAuthModule.validateRequest(SpnegoServerAuthModule.java:284)
at com.sun.enterprise.security.jmac.config.GFServerConfigProvider$GFServerAuthContext.validateRequest(GFServerConfigProvider.java:1171)
at com.sun.web.security.RealmAdapter.validate(RealmAdapter.java:1445)
at com.sun.web.security.RealmAdapter.invokeAuthenticateDelegate(RealmAdapter.java:1323)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:623)
at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:600)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; remaining name 'DC=xxx-ad,DC=int'
at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1983)
at com.sun.jndi.ldap.LdapCtx.doSearchOnce(LdapCtx.java:1914)
at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:1008)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(ComponentContext.java:526)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:159)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:148)
at com.sun.enterprise.resource.naming.JndiProxyObjectFactory.getObjectInstance(JndiProxyObjectFactory.java:164)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:556)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:514)
... 32 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at com.sun.jndi.ldap.Connection.run(Connection.java:820)
... 1 more

#]
Comment by c_krebs [ 08/May/12 07:09 AM ]

We're having the same issue. We're using an external JNDI resource with several hosts in the provider list, such that next LDAP server can take over, if one fails:

asadmin create-jndi-resource --jndilookupname ou=People --restype=javax.naming.DirContext \
--factoryclass=com.sun.jndi.ldap.LdapCtxFactory \
--property java.naming.provider.url="ldap\://ldap-1\:1389 ldap\://ldap-2\:1389"
ldap/user

However, when the first LDAP server is down we're getting these javax.naming.CommunicationException. Only restarting the glassfish instance helps.

Comment by naman_mehta [ 19/Feb/13 08:24 AM ]

Fixed the issue.

Added code to do re-lookup when it comes back.

Comment by naman_mehta [ 19/Feb/13 08:30 AM ]

------------------------------------------------------------------------
r59628 | naman_mehta | 2013-02-19 13:46:29 +0530 (Tue, 19 Feb 2013) | 4 lines
Changed paths:
M /trunk/main/appserver/resources/resources-connector/src/main/java/org/glassfish/resources/naming/JndiProxyObjectFactory.java

Fixing issue: http://java.net/jira/browse/GLASSFISH-15447
External jndi resource fails when ldap resource goes down and come back again.

------------------------------------------------------------------------

Generated at Mon Apr 21 01:26:37 UTC 2014 using JIRA 4.0.2#472.