[ad_1]
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.
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). Now I’m checking the load of VM because the code is running in threads and thinking about what can be wrong.
I’ve also created a ticken in Azure Portal and I have the following answer from the Microsoft:
This error is not coming from Microsoft Graph rather from your clients
socket (otherwise meaning a network error)For these errors, you must start with your networking team to
investigate. There could be a number of networking reasons i.e. 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
[ad_2]