简体   繁体   English

Microsoft.Graph.ServiceException---> System.Net.Sockets.SocketException。 同时获得 TransitiveMemberOf

[英]Microsoft.Graph.ServiceException---> System.Net.Sockets.SocketException. while getting TransitiveMemberOf

I'm seen System.Net.Sockets.SocketException: Connection reset by peer error doing the call to retrieve groups using TransitiveMemberOf method from Microsoft.Graph.dll.我看到System.Net.Sockets.SocketException: Connection reset by peer error执行调用以使用 Microsoft.Graph.dll 中的 TransitiveMemberOf 方法检索组。

 public async Task<List<AdGroup>> GetAllGroupsByUserId(string userId, CancellationToken token)
    {
        _client = GraphConnection.GetGraphClient(_config);
        var memberships = new List<AdGroup>();
        try
        {
            IUserTransitiveMemberOfCollectionWithReferencesRequest? next = null;
            do
            {
                IUserTransitiveMemberOfCollectionWithReferencesPage data;
                if (next == null)
                {
                    var id = Guid.NewGuid().ToString();
                    var options = new List<Option>()
                    {
                        new QueryOption("$top", "999"),
                        new HeaderOption("client-request-id", id)
                    };

                    data = await _client.Users[userId].TransitiveMemberOf.Request(options).Select("id,displayName").GetAsync(token);
                }
                else
                {
                    data = await next.GetAsync(token);
                }

                next = data.NextPageRequest;
                if (data.CurrentPage.Count == 0)
                    break;

                var foundGroups = data.CurrentPage
                    .Select(i =>
                    {

                        if (i is Group group)
                            return new AdGroup()
                            {
                                Id = group.Id,
                                Name = string.IsNullOrWhiteSpace(group.DisplayName) ? group.AdditionalData?["displayName"].ToString() ?? "" : group.DisplayName
                            };
                        if (i is DirectoryRole role)
                            return new AdGroup()
                            {
                                Id = role.Id,
                                Name = string.IsNullOrWhiteSpace(role.DisplayName) ? role.AdditionalData?["displayName"].ToString() ?? "" : role.DisplayName
                            };
                        return null;
                    })
                    .Where(g => g != null && Constants.CONTAINS_LIST.Any(c => g.Name.Contains(c, StringComparison.InvariantCultureIgnoreCase)));
                    
                if (foundGroups != null)
                    memberships.AddRange(foundGroups);

            } while (next != null);
        }
        catch (Exception e)
        {
            _logger.LogError(e, "GetAllGroupsByUserId error");
        }
        return memberships;
    }

I tried to run the code from Azure VM ( I have Linux OS there) as well as from my local machine (Windows OS).我尝试从 Azure VM(那里有 Linux 操作系统)以及本地计算机(Windows 操作系统)运行代码。 Now I'm checking the load of VM because the code is running in threads and thinking about what can be wrong.现在我正在检查 VM 的负载,因为代码在线程中运行并考虑可能出现的问题。

I've also created a ticken in Azure Portal and I have the following answer from the Microsoft:我还在 Azure 门户中创建了一个报价单,我得到了 Microsoft 的以下回答:

This error is not coming from Microsoft Graph rather from your clients socket (otherwise meaning a network error)此错误不是来自 Microsoft Graph,而是来自您的客户端套接字(否则意味着网络错误)

For these errors, you must start with your networking team to investigate.对于这些错误,您必须从您的网络团队开始进行调查。 There could be a number of networking reasons ie your Firewall, Proxy, Loadbalancer, network bandwidth throttling.可能有许多网络原因,例如您的防火墙、代理、负载平衡器、网络带宽限制。

That answer didn't help me a lot, but I'm trying to investigate futher.这个答案对我没有多大帮助,但我正在尝试进一步调查。

I will appreciate any help, thanks我将不胜感激任何帮助,谢谢

In case if someone face the similar issue, I posted the information which helped me to resolve it:如果有人遇到类似问题,我发布了帮助我解决问题的信息:

  1. Increase the number of cores on VM from 4 to 16将 VM 上的核心数量从 4 个增加到 16 个
  2. Decrease the number of tasks from 200 to 100 which were doing the call to MS Graph and some logic将调用 MS Graph 和一些逻辑的任务数从 200 减少到 100
  3. Initialize a new MS Graph client on each iteration inside of the method GetAllGroupsByUserId在 GetAllGroupsByUserId 方法内的每次迭代中初始化一个新的 MS Graph 客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Azure时Visual Studio中的System.Net.Sockets.SocketException - System.Net.Sockets.SocketException in Visual Studio while using Azure System.Net.Sockets.SocketException - System.Net.Sockets.SocketException postgres 连接上的 System.Net.Sockets.SocketException - System.Net.Sockets.SocketException on postgres connection System.Net.Sockets.SocketException 灾难 - System.Net.Sockets.SocketException Disaster 随机获取“ System.Net.Sockets.SocketException:连接尝试失败,因为连接方 - Randomly getting "System.Net.Sockets.SocketException: A connection attempt failed because the connected party System.Net.Sockets.SocketException:&#39;提供了无效的参数&#39; - System.Net.Sockets.SocketException: 'An invalid argument was supplied' System.Net.Sockets.SocketException(0x80004005) - System.Net.Sockets.SocketException (0x80004005) 查找导致异常的确切原因-System.Net.Sockets.SocketException - Finding the exact cause for the exception - System.Net.Sockets.SocketException 类型为“ System.Net.Sockets.SocketException”的Windows天蓝色异常 - Windows azure exception of type “System.Net.Sockets.SocketException ” Azure Function 运行到 System.Net.Sockets.SocketException - Azure Function runs into System.Net.Sockets.SocketException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM