Skip to content

Commit fca55a1

Browse files
authored
[TEST] Wait for async LDAP search to finish (#81197) (#81236)
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
1 parent a45e75d commit fca55a1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/SearchGroupsResolverInMemoryTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131

3232
import java.util.List;
3333
import java.util.concurrent.ExecutionException;
34+
import java.util.concurrent.TimeUnit;
3435

3536
import static org.elasticsearch.xpack.core.security.authc.RealmSettings.getFullSettingKey;
3637
import static org.hamcrest.Matchers.containsString;
3738
import static org.hamcrest.Matchers.instanceOf;
3839
import static org.hamcrest.Matchers.is;
3940
import static org.hamcrest.Matchers.iterableWithSize;
41+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
4042

4143
public class SearchGroupsResolverInMemoryTests extends LdapTestCase {
4244

@@ -77,6 +79,10 @@ public void testSearchTimeoutIsFailure() throws Exception {
7779
assertThat(((LDAPException) cause).getResultCode(), is(ResultCode.TIMEOUT));
7880
} finally {
7981
ldapServers[0].setProcessingDelayMillis(0);
82+
83+
// Wait for the async search to complete or timeout.
84+
// Without this, we might trigger an orphaned thread - see https://github.com/pingidentity/ldapsdk/issues/120
85+
assertBusy(() -> assertThat(connection.getActiveOperationCount(), lessThanOrEqualTo(0)), 2000, TimeUnit.MILLISECONDS);
8086
}
8187
}
8288

0 commit comments

Comments
 (0)