pingidentity / ldapsdk

UnboundID LDAP SDK for Java
Other
334 stars 81 forks source link

AsyncRequestID can recreate Timer while connection is closing #120

Open tvernum opened 2 years ago

tvernum commented 2 years ago

There is race condition between closing a connection and asynchronous results being returned.

LDAPConnection.setClosed will cancel the timer if one exists.

But AsyncRequestID.setResult will call getTimer which will potentially create a new timer thread.

If the async result returns while the connection is in the process of closing (or has just closed) then it will create a new timer that never gets cleaned up, and leaks a thread.

I think there might be a need for getTimer to return null if the connection internals are already closed, and for AsyncRequestID to handle that null case.

dirmgr commented 2 years ago

Thanks for reporting this. I haven't been able to reproduce the problem for myself, but I have committed a set of changes to the LDAP SDK that I think should prevent it from happening.

tvernum commented 2 years ago

Thanks.

Our CI was getting a failure at around 1 in 5k executions, so I can understand why it didn't reproduce for you. I think I ended up running the test about 100k times before I managed to catch it with the right debugging in place to diagnose the cause.

The change in f5d5ccf186c33c1cacae3082394b82044f401c19 looks like it will solve the problem I saw.