kohsuke / com4j

Type-safe Java/COM binding
http://com4j.kohsuke.org/
BSD 2-Clause "Simplified" License
146 stars 78 forks source link

UDP ports not being closed #78

Open goyocasero opened 5 years ago

goyocasero commented 5 years ago

Hi. We're using com4j in our Java 8 application to connect to our Microsoft Active Directory, using the following code: ` _Connection con = com4j.typelibs.ado20.ClassFactory.createConnection(); try { con.provider("ADsDSOObject"); con.open("AD-Anon-Search", "", "", -1/default/);

        _Command cmd = com4j.typelibs.ado20.ClassFactory.createCommand();
        try
        {
            cmd.activeConnection(con);
            cmd.commandText("<GC://" + this.domain + ">;" + filter.encode() + ";" + atributes + ";SubTree");
            _Recordset rs = cmd.execute(Variant.getMissing(), Variant.getMissing(), -1/*default*/);
            try
            {
                if (rs.eof())
                    return nullValue;
                else
                    return mapper.mapRecordSet(rs);
            } finally {
                rs.close();
                rs.dispose();
            }
        } finally {
            cmd.dispose();
        }
    } finally {
        con.close();
        con.dispose();
        COM4J.cleanUp();
    }`

We're noticing that everytime the command executes it opens an UDP connection against our AD, but this connection is never closed. So, after some time, we got all ours UDP ports opened. AFAIK, we're closing everythin up. aren't we? Is there anything else we should do?

kllbzz commented 5 years ago

Hi, At least, you can try write the same code on C# or C++ to find out if the problem in com4j or COM object or in your incorrect usage of it. Basically, if c# copy runs fine without holding all available udp ports, then it means com4j keep something unclosed, btw you can't rely on any cleanup code that called when object is GCed, since you don't know when gc is run, so call all clean/close methods yourself if you don't yet.

ср, 12 дек. 2018 г., 18:36 goyocasero notifications@github.com:

Hi. We're using com4j in our Java 8 application to connect to our Microsoft Active Directory, using the following code: ` _Connection con = com4j.typelibs.ado20.ClassFactory.createConnection(); try { con.provider("ADsDSOObject"); con.open("AD-Anon-Search", "", "", -1/default/);

  _Command cmd = com4j.typelibs.ado20.ClassFactory.createCommand();
  try
  {
      cmd.activeConnection(con);
      cmd.commandText("<GC://" + this.domain + ">;" + filter.encode() + ";" + atributes + ";SubTree");
      _Recordset rs = cmd.execute(Variant.getMissing(), Variant.getMissing(), -1/*default*/);
      try
      {
          if (rs.eof())
              return nullValue;
          else
              return mapper.mapRecordSet(rs);
      } finally {
          rs.close();
          rs.dispose();
      }
  } finally {
      cmd.dispose();
  }

} finally { con.close(); con.dispose(); COM4J.cleanUp(); }`

We're noticing that everytime the command executes it opens an UDP connection against our AD, but this connection is never closed. So, after some time, we got all ours UDP ports opened. AFAIK, we're closing everythin up. aren't we? Is there anything else we should do?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kohsuke/com4j/issues/78, or mute the thread https://github.com/notifications/unsubscribe-auth/AB0px_tt5S_n0Rg7CGrM1jAPrAFxaSDpks5u4SJmgaJpZM4ZPrpj .