JIComServer causes open DCOM connections

2008-07-05
2012-11-29
  • Georg Weber
    Georg Weber
    2008-07-05

    Hello, I had the problem that JIComServer was not cleaning up if it got an error during initialization and therefore the connection to the remote host was not closed. The reason is because JIComServer does not call detach if it gets an error during initialise. Even if I call JISession.destroySession after unsuccessful initialization of JIComServer this does not help, because JISession has no stub assigned. You might be able to reproduce if You throw an IOException at the end of the Stub.attach method (I did not try this). Just be sure that the Java process does not exit and take a look at the network connections (via netstat) after You have called JISession.destroySession.

    Attached You can find a patch which solves the problem:

    Index: src/org/jinterop/dcom/core/JIComServer.java

    --- src/org/jinterop/dcom/core/JIComServer.java    (revision 68)
    +++ src/org/jinterop/dcom/core/JIComServer.java    (working copy)
    @@ -476,6 +476,16 @@
         }
        
        
    +    private void tryDetach() {
    +        try {
    +            detach();
    +        } catch (IOException e) {
    +            if (JISystem.getLogger().isLoggable(Level.WARNING))
    +            {
    +                JISystem.getLogger().warning("Unable to detach during init: " + e);
    +            }
    +        }
    +    }
         private void init () throws JIException
         {
             if (remoteActivation != null && remoteActivation.isActivationSuccessful())
    @@ -483,28 +493,39 @@
                 return;
             }
            
    +        syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
             try {
    -           
    -           
    -            syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
                 attach();
    -            //first send an AlterContext to the IID of the IOxidResolver
    -            getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
    -            getEndpoint().getSyntax().setVersion(0,0);
    -            ((JIComEndpoint)getEndpoint()).rebindEndPoint();
    -           
    -            //setup syntax for IRemoteActivation
    -            syntax = "4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0";
    -            getEndpoint().getSyntax().setUuid(new rpc.core.UUID("4d9f4ab8-7d1c-11cf-861e-0020af6e7c57"));
    -            getEndpoint().getSyntax().setVersion(0,0);
    -            ((JIComEndpoint)getEndpoint()).rebindEndPoint();
    -
    -            remoteActivation = new JIRemActivation(clsid);
    -            call(Endpoint.IDEMPOTENT,remoteActivation);
    -        }catch(FaultException e)
    -        {
    -            remoteActivation = null;
    -            throw new JIException(e.status,e);
    +            try {
    +                //first send an AlterContext to the IID of the IOxidResolver
    +                getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
    +                getEndpoint().getSyntax().setVersion(0,0);
    +                ((JIComEndpoint)getEndpoint()).rebindEndPoint();
    +               
    +                //setup syntax for IRemoteActivation
    +                syntax = "4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0";
    +                getEndpoint().getSyntax().setUuid(new rpc.core.UUID("4d9f4ab8-7d1c-11cf-861e-0020af6e7c57"));
    +                getEndpoint().getSyntax().setVersion(0,0);
    +                ((JIComEndpoint)getEndpoint()).rebindEndPoint();
    +   
    +                remoteActivation = new JIRemActivation(clsid);
    +                call(Endpoint.IDEMPOTENT,remoteActivation);
    +            }catch(FaultException e)
    +            {
    +                tryDetach();
    +                remoteActivation = null;
    +                throw new JIException(e.status,e);
    +            }
    +            catch (IOException e) {
    +                tryDetach();
    +                remoteActivation = null;
    +                throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
    +            }catch (JIRuntimeException e1)
    +            {
    +                tryDetach();
    +                remoteActivation = null;
    +                throw new JIException(e1);
    +            }
             }
             catch (IOException e) {
                 remoteActivation = null;
    @@ -509,12 +530,7 @@
             catch (IOException e) {
                 remoteActivation = null;
                 throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
    -        }catch (JIRuntimeException e1)
    -        {
    -            remoteActivation = null;
    -            throw new JIException(e1);
             }
    -
             // Now will setup syntax for IRemUnknown and the address.
             syntax = "00000143-0000-0000-c000-000000000046:0.0";
             //now for the new ip and the port.

     
    • Hi ,
          Thanks for posting this I will take a look.

      best regards,
      Vikram

       
      • Patch applied.

        Thanks again for pointing this out,
        best regards,
        Vikram