The server is not operational exception freezes my windows service

0

In our intranet we got a windows service with 2 timers in it. First one works each 5 minutes and get Active Directory users list and update Database with it, second works each hour and do some other stuff.

Sometime maintenance work on network starts, and service inner logic catch exception and write it to log. It is always the same one - The server is not operational. After it both timer seems to stop working, but service got status - started, and nothing happend any more.

Exception handling look like this:

void UserSyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    try
    {
        new ADUsersSync().Sync();
    }
    catch(Exception exc) {
        Log.ErrorFormat("UserSyncTimer_Elapsed: Exception {0}", exc);
    }
}

And there is main try catch block inside Sync function:

public void Sync()
{

    try
    {
        DirectoryEntry Ldap = new DirectoryEntry("LDAP://OU=Users,OU=MOS1,OU=CCE,DC=portal,DC=ru");
        DirectorySearcher searcher = new DirectorySearcher(Ldap);
        searcher.Filter = "(&(objectClass=user)(objectCategory=Person)(memberOf:1.2.840.113556.1.4.1941:=CN=All Users,OU=DL,OU=Groups,DC=portal,DC=ru)) ";
        SearchResultCollection _s = searcher.FindAll();
        foreach (SearchResult sr in _s)
        {
        //... some code ..
        }
    }
    catch (Exception e)
    {
        Log.DebugFormat("ADUsersSync Debug: in main catch and exception: {0}",           e.Message);
        Log.Error(e);
    }
}

Logs looks like this:

2014-08-31 14:12:49,956 [10] DEBUG PortalService.BLL.ADUsersSync  - ADUsersSync Debug: in main catch and exception: The server is not operational.

2014-08-31 14:12:49,966 [10] ERROR PortalService.BLL.ADUsersSync  - System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.

   at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
   at PortalService.BLL.ADUsersSync.Sync()
2014-08-31 14:17:50,169 [5] DEBUG PortalService.BLL.ADUsersSync  - ADUsersSync Debug: in main catch and exception: The server is not operational.

2014-08-31 14:17:50,170 [5] ERROR PortalService.BLL.ADUsersSync  - System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindAll()
   at TNTPortalService.BLL.ADUsersSync.Sync()

What can i do to prevent service from freezing?

Also there was memory leak because of not disposing SearchResultCollection, and it consume 1.5GB RAM on server. Wayting for the next fial to make deep check with company it support.

c#
timer
active-directory
windows-services
asked on Stack Overflow Sep 1, 2014 by aleha • edited Sep 29, 2014 by aleha

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0