Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incomplete results returned as network errors occurring during paging are not written #702

Closed
markwahl-msft opened this issue Jun 15, 2021 · 8 comments

Comments

@markwahl-msft
Copy link
Contributor

markwahl-msft commented Jun 15, 2021

In a script that uses a cmdlet to list a large result set, such as try { $res = Get-Mg... -All -ErrorAction Stop} catch { ... } the cmdlet is expected under normal circumstances to page through and return the complete result set, and under abnormal circumstances such as an Internet outage, report a terminating or non-terminating error. The caller indicates with ErrorAction Stop that it wants the PSh runtime to use the catch block for a non-terminating error.

If the network is up the whole time, this script works as expected and a complete result is returned. And, if the network has gone down before the cmdlet starts processing, then an error is caught by the script, as expected.

However, if the network goes down in the middle of processing, after some calls have been made and partial results returned, but not before the last page has been returned, then no error is provided to the script, and incomplete results are returned. For example, there might be 430 entries (5 pages of 100) in the Graph-based service, but if the network goes down partway through, $res.Count is 200 and no error is reported.

This can cause problems for client automation since there is no indication that there is an incomplete result set or what the cause might be, even with -Verbose -Debug present as well.

AB#9914

@ghost ghost added the ToTriage label Jun 15, 2021
@peombwa
Copy link
Member

peombwa commented Jun 15, 2021

Thanks for bringing this to our attention. We will fix it in the next releases.

@peombwa peombwa self-assigned this Jun 15, 2021
@peombwa peombwa added this to the 1.7.0 milestone Jun 15, 2021
@markwahl-msft
Copy link
Contributor Author

FYI also observed that if the service returns a service error (e.g., 500-series result code) for a GET of a page after the first, then this is not being returned (or included in the debug/verbose log).

@peombwa
Copy link
Member

peombwa commented Jun 23, 2021

@markwahl-msft, an exception is always thrown whenever the network goes down and the request times out (100 seconds). e.g., The script below captures a network error as expected, albeit suppressed.

$stopwatch = [System.Diagnostics.Stopwatch]::new()
try {
    Connect-MgGraph
    $stopwatch.Start()
    $messages = Get-MgUserMessage -UserId $env:App_User_Id -All -ErrorAction Stop
}
catch {
    $stopwatch.Stop()
    Write-Error "Something happened!!"
    Write-Host "Elapsed Time: $($stopwatch.Elapsed.TotalSeconds) seconds."
    $_.Exception
    $stopwatch.Reset()
}

image

The network error is indeed suppressed as noted here and will be fixed by #712.

Is there a specific command that's not throwing an exception when a network error occurs?

I'm using the latest SDK (v1.6.0) to test this.

@markwahl-msft
Copy link
Contributor Author

Is there a specific command that's not throwing an exception when a network error occurs?
Yes, a list cmdlet that is paging. When I used Get MgEntitlementManagement AccessPackageAssignment to list all assignments, with -ErrorAction Stop, and the service had 430 result objects to return. In one case, the network connection went down after the second page and the service could not return the data for the third page. Then the cmdlet returned 200 result objects in the pipeline, and did not throw an exception. With ErrorAction Stop the caller should have received an indication that this was not a complete result. I also observed this behavior when the network was up but the Microsoft Graph endpoint returned a 500-series error on that third page, again only 200 (two pages) of data was returned and no indication to the caller that the results were incomplete.

@peombwa
Copy link
Member

peombwa commented Jun 24, 2021

I'm still not able to repro this on my end, even with Get-MgEntitlementManagementAccessPackageAssignment. I'm testing a network connection drop by disconnecting from my wifi and waiting for the request to timeout (100 seconds):

@peter ➜ M $assignments =  $null
@peter ➜ M $assignments = Get-MgEntitlementManagementAccessPackageAssignment -All -ErrorAction Stop
Get-MgEntitlementManagementAccessPackageAssignment_List: C:\Users\peter\Documents\PowerShell\Modules\Microsoft.Graph.Identity.Governance\1.6.0\custom\Get-MgEntitlementManagementAccessPackageAssignment.ps1:159
Line |
 159 |      Microsoft.Graph.Identity.Governance.private\Get-MgEntitlementMana|      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Value cannot be null. (Parameter 'httpResponse')

@peter ➜ M $assignments.count
0
@peter ➜ M $stopwatch = [System.Diagnostics.Stopwatch]::new()
@peter ➜ M try {
>>     Connect-MgGraph
>>     $stopwatch.Start()
>>     $assignments = $null
>>     $assignments = Get-MgEntitlementManagementAccessPackageAssignment -All -ErrorAction Stop
>> }
>> catch {
>>     $stopwatch.Stop()
>>     Write-Error "Something happened!!"
>>     Write-Host "Assignment count: $($assignments.count)."
>>     Write-Host "Elapsed Time: $($stopwatch.Elapsed.TotalSeconds) seconds."
>>     $_.Exception
>>     $stopwatch.Reset()
>> }
Welcome To Microsoft Graph!
Write-Error: Something happened!!
Assignment count: 0.
Elapsed Time: 105.4817364 seconds.

Message        : Value cannot be null. (Parameter 'httpResponse')
ParamName      : httpResponse
TargetSite     : Void .ctor(System.Net.Http.HttpResponseMessage)
StackTrace     :    at Microsoft.Graph.PowerShell.HttpMessageFormatter..ctor(HttpResponseMessage httpResponse)
                    at Microsoft.Graph.PowerShell.Module.Finally(String id, CancellationToken cancellationToken, Func`1
                 getEventData, Func`4 signal)
....

Are you able to repro this with v1.6.0? Also, can you please share your $PSVersionTable.

@peombwa
Copy link
Member

peombwa commented Jun 24, 2021

Also, does this happen intermittently, or it constantly never throws an error when the network is down?

@ghost
Copy link

ghost commented Jul 12, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost
Copy link

ghost commented Jul 17, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost ghost closed this as completed Jul 20, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants