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

Random failures for Set-MgUserPhotoContent #2360

Open
danchevv opened this issue Oct 12, 2023 · 22 comments
Open

Random failures for Set-MgUserPhotoContent #2360

danchevv opened this issue Oct 12, 2023 · 22 comments

Comments

@danchevv
Copy link

Describe the bug

When running the command multiple times in a short amount of times (i.e. a script) the command seems to fail at random.

To Reproduce
Steps to reproduce the behavior:

  1. Have a script that uploads pictures for multiple users - I was able to get this error with batches of up to 20 users.
  2. At some point some user will fail. If you run the single command for that user with the same parameters, it will succeed

Expected behavior
Either a clear error on what the problem was or the picture to be changed successfully.

Debug Output
DEBUG: [CmdletException]: Received exception with message 'HttpRequestException - An error occurred while sending the request. : at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RedirectHandler.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RetryHandler.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.CompressionHandler.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Authentication.Handlers.AuthenticationHandler.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.d__439.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__57.MoveNext()'
DEBUG: [CmdletException]: Received exception with message 'PipelineStoppedException - The pipeline has been stopped. : at System.Management.Automation.MshCommandRuntime._WriteErrorSkipAllowCheck(ErrorRecord errorRecord, Nullable`1 actionPreference)
at System.Management.Automation.MshCommandRuntime.DoWriteError(Object obj)
at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
at System.Management.Automation.MshCommandRuntime.WriteError(ErrorRecord errorRecord, Boolean overrideInquire)
at System.Management.Automation.Cmdlet.WriteError(ErrorRecord errorRecord)
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__57.MoveNext()'

Module Version
Get-Module Microsoft.Graph*

ModuleType Version Name ExportedCommands


Script 2.6.1 Microsoft.Graph.Authentication {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, G...

Environment Data
$PSVersionTable

Name Value


PSVersion 5.1.20348.1850
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.1850
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Screenshots
N/A

Additional context
We are authenticating with a client secret to an application which has the necessary permissions to change the pictures. Again, this seems to work for most users, but in some odd cases it fails for some for no valid reason. Usually it tends to succeed for 80-90% of the users, and on rare occasions it won't fail at all. Is there some throttling mechanism at hand here?

@peombwa
Copy link
Member

peombwa commented Oct 20, 2023

Thanks for bringing this to our attention.

Could you please share the output of $error[0] | fl -Force right after the error has occurred to help us understand the error as we are not able to repro on our end. Also, does error occur in PowerShell 7, the latest version of PowerShell?

@tkudya
Copy link

tkudya commented Oct 23, 2023

@peombwa , we are not using Powershell 7 yet
image

@yudicon
Copy link

yudicon commented Oct 23, 2023

Same here as @tkudya But on every upload try. Same in pwsh7.

@danchevv
Copy link
Author

danchevv commented Oct 24, 2023

Here are the log outputs for Powershell 5:

Exception             : System.Net.Http.HttpRequestException: An error occurred while sending the 
                        request. ---> System.Net.WebException: The request was aborted: The 
                        request was canceled. ---> System.IO.IOException: Cannot close stream 
                        until all bytes are written.
                           at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean 
                        aborting)
                           --- End of inner exception stack trace ---
                           at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean 
                        aborting)
                           at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState 
                        closeState)
                           at System.Net.ConnectStream.Dispose(Boolean disposing)
                           at System.IO.Stream.Close()
                           at System.Net.Http.HttpClientHandler.<>c__DisplayClass109_0.<GetRequestS
                        treamCallback>b__0(Task task)
                           --- End of inner exception stack trace ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RedirectHandler.<Se
                        ndAsync>d__5.MoveNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RetryHandler.<SendA
                        sync>d__7.MoveNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.CompressionHandler.
                        <SendAsync>d__1.MoveNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Graph.PowerShell.Authentication.Handlers.AuthenticationHand
                        ler.<SendAsync>d__12.MoveNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.Mov
                        eNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.Mov
                        eNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at 
                        Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent>d__439.MoveNext()
                        --- End of stack trace from previous location where exception was thrown 
                        ---
                           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebugg
                        erNotification(Task task)
                           at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.<Process
                        RecordAsync>d__57.MoveNext()
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [Set-MgUserPhotoContent_Set], HttpRequestException
FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Set-MgUserPhotoContent<Process>, C:\Program Files\WindowsPowerShell\Modu
                        les\Microsoft.Graph.Users\2.6.1\exports\ProxyCmdletDefinitions.ps1: line 
                        47761
                        at <REDACTED due to PII>, 
                        <REDACTED due to PII>.ps1: line 204
                        at <ScriptBlock>, 
                        <REDACTED due to PII>.ps1: line 314
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails      : 

I'll post an update once I test with Powershell 7.

@tschwa21
Copy link

I am having the same issue. On PowerShell 7 with Microsoft.Graph.Users module version 2.2. Below is the error

`writeErrorStream : True
Exception : System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: The request was canceled. ---> System.IO.IOException: Cannot
close stream until all bytes are written.
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
--- End of inner exception stack trace ---
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.ConnectStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.Net.Http.HttpClientHandler.<>c__DisplayClass109_0.b__0(Task task)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RedirectHandler.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.RetryHandler.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Kiota.Http.HttpClientLibrary.Middleware.CompressionHandler.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Authentication.Handlers.AuthenticationHandler.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Graph.PowerShell.Users.<UserSetPhotoContent_Call>d__441.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Users.d__439.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set.d__57.MoveNext()
TargetObject :
CategoryInfo : NotSpecified: (:) [Set-MgUserPhotoContent_Set], HttpRequestException
FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Set-MgUserPhotoContent, C:\Users\thomas.schwoerer\Documents\WindowsPowerShell\Modules\Microsoft.graph.users\2.2.0\exports\ProxyCmdletDefinitions.ps1: line 47552
at , C:\Scripts\Weekly Maintenance\Sync User Photos Changes Only.ps1: line 274
PipelineIterationInfo : {0, 1}
PSMessageDetails :

@danchevv
Copy link
Author

As of now, I have not been able to reproduce the issue with Powershell 7. I installed it via the x64 MSI file and did not add it to the path nor ticked any other checkbox during the installation. Seems to be working for now.

@peombwa
Copy link
Member

peombwa commented Oct 25, 2023

As of now, I have not been able to reproduce the issue with Powershell 7. I installed it via the x64 MSI file and did not add it to the path nor ticked any other checkbox during the installation. Seems to be working for now.

Thanks for confirming and providing the stack trace. We will use this issue to investigate why the error is occurring in PowerShell 5.1.

@tschwa21, you may want to first update your SDK to version 2.8.0. Several improvements and bug fixes have been made to the SDK since v2.2.0. See release notes at https://github.com/microsoftgraph/msgraph-sdk-powershell/releases for more details.

@ztrhgf
Copy link

ztrhgf commented Nov 6, 2023

Same issue here on 2.8.0 version. On my Windows 10 system it works fine, but on Server 2016 it fails almost for every user with error "An error occurred while sending the request."

What seems to solve the issue on the Server OS is to resize the images to the height of 188 pixels and add some wait time between Set-MgUserPhotoContent calls.

@yudicon
Copy link

yudicon commented Nov 6, 2023

In my case there is no chance to get a photo uploaded. Regardless of the operating system. What is the correct way to handle this? The retirement of the old powershell commands is soon and error handling or error information of the new Graph APIs is horrible. We can't just sit around try to change sizes and hope that the request will go through. Please provide accurate error messages, we can work with.

@tschwa21
Copy link

tschwa21 commented Nov 7, 2023

As of now, I have not been able to reproduce the issue with Powershell 7. I installed it via the x64 MSI file and did not add it to the path nor ticked any other checkbox during the installation. Seems to be working for now.

Thanks for confirming and providing the stack trace. We will use this issue to investigate why the error is occurring in PowerShell 5.1.

@tschwa21, you may want to first update your SDK to version 2.8.0. Several improvements and bug fixes have been made to the SDK since v2.2.0. See release notes at https://github.com/microsoftgraph/msgraph-sdk-powershell/releases for more details.

Still having the issue on 2.8.0.

@TheEnderPrime
Copy link

I am also having this issue on PS5.1 with SDK 2.8.0. Every single photo I try to upload causes the error.

@dclarkSSOE
Copy link

dclarkSSOE commented Nov 18, 2023

Also having this issue with PS5.1. Tried upgrading to 2.9.1 and still seeing it.

@jasmindboesch
Copy link

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://graph.microsoft.com/v1.0/users//photo/$value

Headers:
FeatureFlag : 00000043
Cache-Control : no-store, no-cache
User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22621; de-AT),PowerShell/7.3.9
Accept-Encoding : gzip
SdkVersion : graph-powershell/2.8.0
client-request-id : 9f4ce00b-bae3-4b51-9791-abd5e7d445b8

In PowerShell 7 with graph 2.8.0 it worked now.

@tkudya
Copy link

tkudya commented Jan 11, 2024

I am still having issues on Powershell 5.1 with graph 2.11.1

@jamie-oconnell
Copy link

Similar issue with Set-MgDriveItemContent which I believe uses the same dependencies. Most common if trying to upload files sequentially. Workaround seems to be add delay between uploads.

@MaKraMc
Copy link

MaKraMc commented Jun 20, 2024

This is still happening with module version 2.19.0 in PS5.1 Desktop.

@nicolaibaralmueller
Copy link

Same error using Azure Automation account runbook with powershell 5.1. All MgGraph updated to latest.

@PSBoon825
Copy link

Hello, is there no solution to this issue? Still not working with 2.20.0... I was forced to use this command since Set-UserPhoto was deprecated but Set-MgUserPhotoContent does not work...

I can't find any solution on the Internet.

Getting the same errors:
Set-MgUserPhotoContent : An error occurred while sending the request.
CategoryInfo : NotSpecified: (:) [Set-MgUserPhotoContent_Set], HttpRequestException
+ FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.SetMgUserPhotoContent_Set

Thanks!

@tkudya
Copy link

tkudya commented Jul 24, 2024

@PSBoon825 - I have converted my script to use powershell graph api instead, its more reliable than this command

@ztrhgf
Copy link

ztrhgf commented Jul 24, 2024

@PSBoon825 I will repeat myself, but what "solved" this issue for me was to resize the images to the height of 188 pixels and add some wait time between Set-MgUserPhotoContent calls.

@PSBoon825
Copy link

@tkudya Thanks for the hint, this looks much more complicated though since I'm not experienced with API calls. Do you happen to have some example code?

@PSBoon825
Copy link

@ztrhgf Thanks for your reply. This happens to me even when running the command only once sometimes. Sometimes it works, sometimes it doesn't. Very unreliable. I read somewhere that the images should be converted to 648x648 for the MS cloud uploads, so isn't 188 against the "best practice"?

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