DsGetDcName Timeout

Today I was looking for the source of frequent delays when setting permissions from my new application SetACL Studio. I sprinkled the code with timestamped debug statements like these…

System.Diagnostics.Debug.WriteLine(DateTime.Now + " - 1");
// Do something
System.Diagnostics.Debug.WriteLine(DateTime.Now + " - 2");

…and found that the delays always had a duration of seven seconds. Wait - “inexplicable” delays of constant length - that smells of timeouts!

And indeed, by stepping into the underlying unmanaged code it was pretty easy to identify the call causing the timeouts:

if (DsGetDcName (NULL, sDomainName, NULL, NULL, 0, &pdcInfo) == ERROR_SUCCESS)

This happened if sDomainName was equal to the local computer name, i.e. when looking for a (nonexistent) domain with the name of my computer.

I fixed that line by adding a check if sDomainName is different from the local computer name:

CString sComputername;
sComputername.GetEnvironmentVariable(L"computername");
if (sComputername.CompareNoCase(sDomainName) != 0)
{
   // Call DsGetDcName here
}

Comments

Related Posts

Latest Posts

Beautiful Slide Decks from Markdown: Presenting with Slidev

Beautiful Slide Decks from Markdown: Presenting with Slidev
Would you like to get away from PowerPoint and author slide decks in Markdown? Then Slidev may be just what you’re looking for. It’s a web app for presentations. The fact that it’s geared towards developers shouldn’t put you off. After all, who isn’t a developer these days, with AI? Slidev comes with the beautiful Tahta themes and supports features like syntax highlighting and animations. Export options to PDF and PPTX allow for easy sharing. This article shows how to get started.
Applications