1

We're enumerating through thousands of users in a test AD. The whole thing can run in about an hour. But sometimes, for a single user, the following few lines of code will get stuck for about 10 hours.

This doesn't always happen, and when it does it can happen to any AD user.

        using (DirectoryEntry de = new DirectoryEntry(String.Format(@"LDAP://{0}/<GUID={1}>", host, objectGUID), admin, password, server.AuthenticationMethod))
        {
            try
            {
                dn = (string)de.Properties["distinguishedName"][0];
            }
            catch
            {
                // log it...
            }
        }

After the long delay things continue as if nothing was wrong.

What could cause this delay?

6
  • what else is happening on the server when this happens? Oct 13, 2015 at 15:18
  • Nothing that seems significant. The AD server doesn't have high CPU or memory usage. NETSTAT doesn't show signs of port exhaustion. The client is also running internal ASP.NET websites, but nothing taxing.
    – x5657
    Oct 13, 2015 at 15:22
  • are any errors showing in the event viewer? are there any events with the active directory when this happens? Oct 13, 2015 at 15:32
  • No errors either side in Event Viewer. Outside of Event Viewer, how can I check for the events with active directory that you mentioned?
    – x5657
    Oct 13, 2015 at 15:54
  • Your try has no catch, this code shouldn't even compile. I assume youre not giving us the whole picture.
    – Ashigore
    Oct 14, 2015 at 12:16

1 Answer 1

1

TL;DR Enable AuthenticationTypes.Secure to fix this.

I created a test application that was able to reproduce this problem on demand. All the test application did was to start up 4 threads, each thread containing an infinite while loop. In the while loop I created a new DirectoryEntry and called RefreshCache on it. Quite often, especially on startup, one of the threads would encounter the following exception

COMException -2147016643 "A decoding error has occurred."

This error is also known as 0x8007203D aka -2147016643 aka 2147950653

When this exception was seen in one of the threads, one or more of the other threads would hang on the call to RefreshCache.

In the DirectoryEntry constructor we were not including AuthenticationTypes.Secure. Secure is a default flag, but because we were setting other AuthenticationTypes flags we should have manually included Secure too. Not sure why, but DirectoryServices behaves much more nicely under multi-threading when Secure mode is enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.