8 Replies Latest reply on Aug 24, 2011 3:35 AM by ronsen

    InitialContext#lookup does not timeout

    stianst

      I've got an issue where InitialContext#lookup will hang forever doing a lookup if there is a problem with the network. I appreciate this is the default settings of the TCP sockets to wait forever, so I've tried to configure the timeout using 'jnp.timeout' and 'jnp.sotimeout', but it still waits forever.

       

      Hashtable<String, String> env = new Hashtable<String, String>();
      env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.provider.url", "jnp://10.9.1.11:1099");
      env.put("java.naming.factory.url.pkgs", "org.jboss.naming");
      env.put("jnp.socketFactor", "org.jnp.interfaces.TimedSocketFactory");
      env.put("jnp.timeout", "1000");
      env.put("jnp.sotimeout", "1000");
      
      InitialContext ctx = new InitialContext(env);
      
      HelloWorld world = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
      world.sayHello("hello");
      
      // disconnect network here
      
      world = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
      world.sayHello("hello");
      

       

      In the above example if the network is disconnected before the first lookup it times out as expected, but if the network is disconnected between the first and the second lookup it doesn't timeout at all (waited 10 min+).