pingidentity / ldapsdk

UnboundID LDAP SDK for Java
Other
331 stars 79 forks source link

NullPointerException occured inside LDAPConnectionInternals / ASN1Buffer / ByteStringBuffer #100

Open chrko opened 3 years ago

chrko commented 3 years ago

Hi,

while using a single LDAPConnection a NullPointerException occurred inside the framework. Unfortunately we currently don't print the full stack trace:

com.unboundid.ldap.sdk.LDAPException: An error occurred while encoding the LDAP message or sending it to ***:  NullPointerException(write(ByteStringBuffer.java:1965) / writeTo(ASN1Buffer.java:1033) / sendMessage(LDAPConnectionInternals.java:612) / sendMessage(LDAPConnection.java:4640) / processAsync(ModifyRequest.java:792) / process(ModifyRequest.java:687) / modify(LDAPConnection.java:2993) / ...), ldapSDKVersion=5.1.1, revision=580fabe31b0752099ccd9a835fe7da96e8251e28
        at com.unboundid.ldap.sdk.LDAPConnectionInternals.sendMessage(LDAPConnectionInternals.java:669) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.ldap.sdk.LDAPConnection.sendMessage(LDAPConnection.java:4640) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.ldap.sdk.ModifyRequest.processAsync(ModifyRequest.java:792) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.ldap.sdk.ModifyRequest.process(ModifyRequest.java:687) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.ldap.sdk.LDAPConnection.modify(LDAPConnection.java:2993) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at [our internal code]
Caused by: java.lang.NullPointerException
        at com.unboundid.util.ByteStringBuffer.write(ByteStringBuffer.java:1965) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.asn1.ASN1Buffer.writeTo(ASN1Buffer.java:1033) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        at com.unboundid.ldap.sdk.LDAPConnectionInternals.sendMessage(LDAPConnectionInternals.java:612) ~[unboundid-ldapsdk-5.1.1.jar:5.1.1]
        ... 9 more

As we tried to tackle down this exception, it seems to occur inside the LDAPConnectionInternals as race condition between closing the connection and setting outputStream = null and still trying to send messages. We are currently using the asynchronous operation mode as default. Closing the connection must have happened due to external circumstances, probably network errors which occurred this day.

We haven't observed this twice and couldn't reproduce it.

dirmgr commented 3 years ago

Thanks for reporting this. I agree that it's likely a race condition that may occur if a connection has become invalidated. I have just committed a change that will hopefully address this by avoiding the NPE and hopefully at least providing a better error message.