ldapsdk icon indicating copy to clipboard operation
ldapsdk copied to clipboard

AsyncRequestID can recreate Timer while connection is closing

Open tvernum opened this issue 3 years ago • 2 comments

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.

tvernum avatar Dec 01 '21 04:12 tvernum

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.

dirmgr avatar Dec 01 '21 20:12 dirmgr

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.

tvernum avatar Dec 02 '21 02:12 tvernum