Skip to content

Commit

Permalink
[TEST] Wait for async LDAP search to finish (#81197)
Browse files Browse the repository at this point in the history
LDAP SDK has a race condition where closing a connection while an async
search is still executing could lead to a Timer thread being orphaned.
See: pingidentity/ldapsdk#120 This commit
changes SearchGroupsResolverInMemoryTests so that it waits for the
pending async search to complete (or timeout) before returning. This
ensures that when the close the connection the Timer thread is cancelled
(and stays cancelled). Resolves: #80305
  • Loading branch information
tvernum authored Dec 2, 2021
1 parent 332fdd5 commit 591f551
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.xpack.core.security.authc.RealmSettings.getFullSettingKey;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.hamcrest.Matchers.lessThanOrEqualTo;

public class SearchGroupsResolverInMemoryTests extends LdapTestCase {

Expand Down Expand Up @@ -77,6 +79,10 @@ public void testSearchTimeoutIsFailure() throws Exception {
assertThat(((LDAPException) cause).getResultCode(), is(ResultCode.TIMEOUT));
} finally {
ldapServers[0].setProcessingDelayMillis(0);

// Wait for the async search to complete or timeout.
// Without this, we might trigger an orphaned thread - see https://github.com/pingidentity/ldapsdk/issues/120
assertBusy(() -> assertThat(connection.getActiveOperationCount(), lessThanOrEqualTo(0)), 2000, TimeUnit.MILLISECONDS);
}
}

Expand Down

0 comments on commit 591f551

Please sign in to comment.