Socket closed exception

Hi Experts,

I have a web application with 2 war apps. I use the same code in both war application to get the initial context (code below). It works just fine with same credentials in the first app but throws the following exception in the second app.

app is deployed on websphere  application server 6.1


[3/30/10 14:31:23:481 EDT] 00000020 SystemErr     R javax.naming.ServiceUnavailableException: 192.168.1.65:636; socket closed
[3/30/10 14:31:23:481 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.Connection.readReply(Connection.java:439)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapClient.ldapBind(LdapClient.java:355)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:207)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2652)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:298)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:190)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:208)
[3/30/10 14:31:23:482 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:151)
[3/30/10 14:31:23:483 EDT] 00000020 SystemErr     R       at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:81)
[3/30/10 14:31:23:483 EDT] 00000020 SystemErr     R       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:679)
[3/30/10 14:31:23:483 EDT] 00000020 SystemErr     R       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:259)
[3/30/10 14:31:23:483 EDT] 00000020 SystemErr     R       at javax.naming.InitialContext.init(InitialContext.java:235)
[3/30/10 14:31:23:483 EDT] 00000020 SystemErr     R       at javax.naming.InitialContext.<init>(InitialContext.java:209)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:93)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at com.bci.ldap.LDAPManager.getInitialContext(LDAPManager.java:63)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at com.bci.ldap.LDAPManager.<init>(LDAPManager.java:29)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at com.bci.ldap.services.LDAPEmployee.changePassword(LDAPEmployee.java:15)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at com.bci.servlet.ChangePassword.doPost(ChangePassword.java:44)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at com.bci.servlet.ChangePassword.doGet(ChangePassword.java:27)
[3/30/10 14:31:23:484 EDT] 00000020 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1095)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:569)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
[3/30/10 14:31:23:485 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
[3/30/10 14:31:23:486 EDT] 00000020 SystemErr     R       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
[3/30/10 14:31:23:487 EDT] 00000020 SystemErr     R       at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
[3/30/10 14:31:23:488 EDT] 00000020 SystemErr     R       at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
[3/30/10 14:31:23:488 EDT] 00000020 SystemErr     R       at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
[3/30/10 14:31:23:488 EDT] 00000020 SystemErr     R       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
private DirContext getInitialContext(
      String protocol, 
      String hostname, 
      int port,
      String username, 
      String password, 
      String keystore)
                throws NamingException {

                String providerURL =
                    new StringBuffer("")
                                .append(protocol)
                                .append("://")
                        .append(hostname)
                        .append(":")
                        .append(port)
                        .toString();
                
                System.setProperty("javax.net.ssl.keyStore", keystore); 

                Properties props = new Properties();
                props.put(Context.INITIAL_CONTEXT_FACTORY,
                          "com.sun.jndi.ldap.LdapCtxFactory");
                props.put(Context.PROVIDER_URL, providerURL);

                if ((username != null) && (!username.equals(""))) {
                    props.put(Context.SECURITY_AUTHENTICATION, "simple");
                    props.put(Context.SECURITY_PRINCIPAL, username);
                    props.put(Context.REFERRAL, "ignore");
                    if(SSLEnabled.equalsIgnoreCase("1"))
                        props.put(Context.SECURITY_PROTOCOL, "SSL");
                    props.put(Context.SECURITY_CREDENTIALS,
                        ((password == null) ? "" : password));
                }

                return new InitialDirContext(props);
            }

Open in new window

bcisystemsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VenabiliCommented:
Does it happen only when both run at the same time or even if the first one is not doing anything and only the second one is running? Is it always the same the one that is failing? Had you try redeploying the war (thinking here that maybe you are not running the same code exactly?)? Do you call the method with the same parameters?
0
bcisystemsAuthor Commented:
No they are not running the same time. First one runs fine. And second one throws this. After that first one fails as well. Second on always fails.

Thanks
S
0
VenabiliCommented:
Sounds like a restriction of the number of connections between the servers. Let me think where this might have happened....  It is definitely not a code issue
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

bcisystemsAuthor Commented:
I havent had any new improvements on this. Admin can close the questions and retrun the points.
0
AdminRAMCommented:
Do you have any load balancer infornt of LDAP server ? if so check the following information

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

load balancer for LDAP failover then you need to make sure follow the given below setup.

If they want to use reuse connection on WAS then they need to Enabled Session Affinity on load balancer
If they want disable Session Affinity on load balancer then they must disable reuse connection on WAS

This is working as design.. Disable the Reuse Connection field only if you use routers to send requests to multiple LDAP servers, and if the routers do not support affinity. Leave this field enabled for all other situations.


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

Reuse  connection

    Specifies whether the server reuses the Lightweight Directory Access Protocol (LDAP) connection. Clear this option only in rare situations where a router is used to distribute requests to multiple LDAP servers and when the router does not support affinity.

    Default:       Enabled
    Range:       Enabled or Disabled

    Important: Disabling the Reuse connection option causes WebSphere Application Server to create a new LDAP connection for every LDAP search request. This situation impacts system performance if your environment requires extensive LDAP calls. This option is provided because the router is not sending the request to the same LDAP server. The option is also used when the idle connection timeout value or firewall timeout value between WebSphere Application Server and LDAP is too small.

    If you are using WebSphere Edge Server for LDAP failover, you must enable TCP resets with the Edge server. A TCP reset causes the connection to be immediately closed, and a failover to the backup server. For more information, please see "Sending TCP resets when server is down" at http://www-3.ibm.com/software/webservers/appserv/doc/v50/ec/infocenter/edge/LBguide.htm#HDRRESETSERVER and the Edge Server V2 - TCP Reset feature in PTF #2 described in: ftp://ftp.software.ibm.com/software/websphere/edgeserver/info/doc/v20/en/updates.pdf.
------------------------------------------------------------------------------------------------------------

see disabling reuse connection will help.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AdminRAMCommented:
Thank you very much for points. I appreciate it.

Have a good day
AdminRam
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.