pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
654 stars 337 forks source link

[BUG] New-PnPsite delay in PnP.PowerShell 2.5.0 #4108

Open wfi-jonas opened 1 month ago

wfi-jonas commented 1 month ago

Reporting an Issue or Missing Feature

I have a provisioning script for sites that uses new-PnPsite in an Azure Function App. When I upgraded my script to use 2.5.0 instead of 2.3.0, the function times out. When I rollback it works perfectly fine and create the site within seconds.

In order to test more I created a simple measure script with only the command new-pnpsite that I ran locally and in the Azure Function App to measure the delay, these are the results (3 tests for each version):

Locally 2.3.0 : 4s37 4s03 4s36 2.5.0 : 4s49 3s89 3s09

Azure function app 2.3.0 : 2s03 5s26 6s65 2.5.0 : timeout (2m40s) timeout (2m40s) timeout (2m40s)

Expected behavior

The site gets created in 2-6 seconds.

Actual behavior

timeout of the function after 2minutes 40 seconds.

Steps to reproduce behavior

Azure function app relevant details:

The script I used to test:

param($Request, $TriggerMetadata) import-module pnp.powershell -RequiredVersion "2.5.0" $c = connect-pnponline -url "https://tenantname-admin.sharepoint.com" -ManagedIdentity -returnconnection try{ $title ="Engine Test 27" $url = "https://tenant name.sharepoint.com/sites/$($title -replace ' ','')" $owner = "my email" $sitedesign = "any design id, or remove it as it doesn't affect the delay" $lcid = 1043 $measure = measure-command { $request = new-pnpsite -connection $c -title $title -sitedesignid $sitedesign -Lcid $lcid -owner $owner -url $url -Type CommunicationSite -wait write-output $request } write-output $measure.TotalSeconds }catch{ write-output $Error[0].Exception -ForegroundColor Red $streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) $ErrResp = $streamReader.ReadToEnd() $streamReader.Close() write-output $ErrResp -ForegroundColor Red }

What is the version of the Cmdlet module you are running?

Tested with PnP PowerShell 2.5.0 and 2.3.0.

Which operating system/environment are you running PnP PowerShell on?

jackpoz commented 1 month ago

Does this happen only when using -ManagedIdentity to connect ? Can you test it with certificate authentication just as a test ?

wfi-jonas commented 1 month ago

I’ve never used anything else when running in functions or runbooks. Locally on my machine with interactive both versions where working fine, provisioning was done in 2-6 seconds.

gautamdsheth commented 4 weeks ago

@wfi-jonas - can you do a perf on just the connect-pnponline with managed identity and let us know ? We did bump the MSAL to the latest version, so maybe that could be the issue ?

wfi-jonas commented 3 weeks ago

What do you mean by perf?

gautamdsheth commented 3 weeks ago

@wfi-jonas - sorry I meant , can you just measure the difference in connect-pnponline between these 2 versions ?

wfi-jonas commented 3 weeks ago

Sorry but that doesn’t make sense. In my measure script above I don’t take into account the time it takes to connect because I saw there was no delay there. So I only measured what I found was the causing the delay.

Is new-pnpsite perhaps targeting different urls? In the changelog I didn’t see any update for this command, but perhaps some change slipped in between 2.3.0 and 2.5.0. Perhaps some dependency on this command?

wfi-jonas commented 3 weeks ago

IMG_6232

wfi-jonas commented 3 weeks ago

Hm I don’t see anything wrong in this change..

gautamdsheth commented 2 weeks ago

The only change that we have done is update MSAL.NET that we use for authentication to the latest version . We were using an older version which had security vulnerabilities, so we bumped it to the latest version. No other change was done related to site provisioning.

gautamdsheth commented 2 weeks ago

@wfi-jonas - can you please try again with tomorrow's or latest nightly builds again ? We made some changes to token fetching and other things, maybe that helps ?

wfi-jonas commented 1 week ago

hello @gautamdsheth , I'm currently not in the office. I'll test this later this week. Thank you for looking into this!