dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

LdapConnection.GetPartialResults() fails with timeout in Linux #100442

Open Chebura opened 7 months ago

Chebura commented 7 months ago

Description

Hi! I use System.DirectoryServices.Protocols LdapConnection.GetPartialResults() with AD. I've found that behavior of client at Windows and Linux is differs.

"System.DirectoryServices.Protocols" Version="8.0.0" (net8)

At windows it work as expected. At linux GetPartialResults() throws error with timeout:

System.DirectoryServices.Protocols.LdapException: The operation was aborted because the client side timeout limit was exceeded. 
   at System.DirectoryServices.Protocols.LdapPartialResultsProcessor.GetPartialResults(LdapPartialAsyncResult asyncResult)

Increasing the timeout causes the operation stuck (operation never ends).

I don't understand, how it must be used properly for Linux.

Usage:

        var sendRequestAsyncResult = ldapConnection.BeginSendRequest(request, PartialResultProcessing.ReturnPartialResults, null, ldapConnection);
        var result = new List<SearchResultEntry>();
        while (!cancellationToken.IsCancellationRequested && !sendRequestAsyncResult.IsCompleted)
        {
            PartialResultsCollection partialResults;
            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (sendRequestAsyncResult.IsCompleted)
                    return result;
                partialResults = ldapConnection.GetPartialResults(sendRequestAsyncResult);
            }
#pragma warning disable S2737
            catch (DirectoryOperationException e) when (e.Message.Equals("The size limit was exceeded", StringComparison.Ordinal))
            {
                throw;
                //return result;
            }
#pragma warning restore S2737
            var entries = partialResults.OfType<SearchResultEntry>().ToList();
            if (entries.Count > 0) //in Linux count is 0
            {
                result.AddRange(entries);
            }
        }

If I use SendRequest(), it's works correctly. GetPartialResults() didn't work correctly with same request.

Reproduction Steps

use LdapConnection.GetPartialResults() and SendRequests(), results are differs.

Expected behavior

IMHO, results of GetPartialResults() process and SendRequests() must be equal.

Actual behavior

timeout occurs without any understandable reasons

Regression?

No response

Known Workarounds

No response

Configuration

Linux (ubuntu 20.04) ActiveDirectory LDAPv3

Other information

No response

buyaa-n commented 7 months ago

At windows it work as expected. At linux GetPartialResults() throws error with timeout:

Increasing the timeout causes the operation stuck (operation never ends).

I don't understand, how it must be used properly for Linux.

The Windows implementation has been there for many years and mature, the Linux implementation added later and could have issue/bug. Tag @joperezr if he knows a workaround or any pointer for this issue