Console icon indicating copy to clipboard operation
Console copied to clipboard

Stack empty error when using Sitecore PowerShell Extensions dialog box

Open ashokkarutur opened this issue 5 years ago • 22 comments

Expected Behavior

Please describe the expected behavior.

Sitecore PowerShell Extensions dialog box shouldn't throws any error if we perform any action parallel

Actual Behavior

Please describe the actual behavior. Sitecore PowerShell Extensions dialog box throws a stack empty error when publishing is performed in parallel

Steps to Reproduce the Problem

1.Open Sitecore PowerShell Extensions dialog box (e.g. “Create a new SXA site”) 2. Parallel open site in private window and publish an item 3. Come back to normal window click any button on the Sitecore PowerShell Extensions dialog box 4. You will see a stack empty error

Raised sitecore ticket, bug reference number: 438156

Error: [InvalidOperationException: Stack empty.] System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +60 System.Collections.Generic.Stack`1.Pop() +76 Spe.Commands.Interactive.Messages.ShowMultiValuePromptMessage.ProcessResult(Boolean hasResult, String sig) +120 Spe.Commands.Interactive.Messages.BasePipelineMessageWithResult.Pipeline(ClientPipelineArgs args) +451

Please include the version number of SPE and Sitecore. Sitecore 9.3

  • [ YES] Tested issue with clean install of Sitecore and the latest available version of SPE.

  • [NO ] Asked questions on the Sitecore Slack Chat channel.

  • [ YES] Reviewed questions and answers on the Sitecore Stack Exchange.

ashokkarutur avatar Oct 05 '20 06:10 ashokkarutur

Can you please provide some screenshots or animated gif showing how you reproduce the issue?

michaellwest avatar Oct 05 '20 06:10 michaellwest

Can you please provide some screenshots or animated gif showing how you reproduce the issue?

Hope this helps

https://www.screencast.com/t/lwQAzEoDFtY

I raised with sitecore support teams. They suggested me to connect with you

ashokkarutur avatar Oct 05 '20 06:10 ashokkarutur

Interesting.

Does it happen if the second window is logged in as a different user following the same steps?

What about if you close the SPE window before hitting ok on the publish dialogue to close?

michaellwest avatar Oct 05 '20 06:10 michaellwest

Interesting.

Does it happen if the second window is logged in as a different user following the same steps? yes What about if you close the SPE window before hitting ok on the publish dialogue to close? -Only on clicking ok in publish dialogue, we see this error

ashokkarutur avatar Oct 05 '20 06:10 ashokkarutur

Hi Michaellwest,

Could you please provide a workaround/fix for this issue.

We are using Sitecore PowerShell Extensions dialog box to create a Article page. Where authors can create easily from sitecore desktop. At the same time there are chance from other authors uses the publishing options. This may breaks article creation flow.

Regards, Ashok

ashokkarutur avatar Oct 05 '20 08:10 ashokkarutur

I'll certainly have a look at it. This is a community supported module. You are more than welcome to submit a PR if you have a possible solution in mind.

michaellwest avatar Oct 05 '20 11:10 michaellwest

Hi Michaellwest,

I noticed this issue occurs when we are using only a Interactive Dialogs pop-up cmd "Read-Variable".

Do we any alternative PS dialog box command to read variables?

Regards, Ashok Karuturi

ashokkarutur avatar Oct 08 '20 06:10 ashokkarutur

Hi Michaellwest,

Do we have any update on this issue ?

Regards, Ashok Karuturi

ashokkarutur avatar Nov 02 '20 15:11 ashokkarutur

Hi Michaealweat,

Please find the sample code below. which we are using to create an article from a desktop view (https://www.screencast.com/t/v4v2urvaf3 )

This Article flow creating process helps our content editors to create a new article quick and easy with less sitecore knowledge. But when a parallel publishing happens from any user we are facing Stack Empty error. Kindly check the code and please provide if any workaround available for this.

Sample Code:

# Article Creation
#
Import-Function Validate-PowerShell


$sourceItem=$null
$itemName=$null

$dialogParams = @{
    Title = "Create News Article Page"
	Description = "Please select the below options"
    OkButtonName = "Create"
    CancelButtonName = "Close"
    Icon = "Office/32x32/newspaper.png"
	width = "600"
	height = "600"
    ShowHints = $true
    Parameters = @(
		@{
            Name = "itemName"
            Title = "Enter a name for the News Article:"
            Mandatory = $true
        }
        @{
            Name = "sourceItem"
            Title = "Select a News Article Group:"
            Editor = "droplist"
            Source = "query:/sitecore/content/IPP/News/Home//*[@@templatename='News Home Page']"
            Mandatory = $true
        }
    )
    Validator = {
        $selectedState = $variables.sourceItem.Value
 
        if ($selectedState.TemplateID -ne "{8CEF8227-380A-4B96-8F1D-5F6FEDB6DC5A}") {
            $variables.sourceItem.Error = "Please choose a valid News article Page."
        }
		$enteredText = $variables.itemName.Value
        if($enteredText){
			if ($enteredText -notmatch "^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$") {
				$variables.itemName.Error = "$($enteredText) is not a valid name."
			}
         }   
    }
}
 
$dialogResult = Read-Variable @dialogParams

if($dialogResult -ne "ok"){
	Exit
}


if($itemName){
    try{
		    $item = New-Item -Path "master:$($sourceItem.Paths.FullPath)" -Name $itemName -ItemType "/sitecore/templates/Project/IPP/News Page"
			#Import-Function Update-NewsItems
			#Update-NewsItems $item
			$editURL="/?sc_mode=edit&sc_itemid=$($item.ID)&sc_lang=en&sc_site=News"  
			Invoke-JavaScript -Script `
					"window.open('$($editURL)', '_blank')"

	 }
    catch
    {
        
    }
}

Error [InvalidOperationException: Stack empty.] System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +60 System.Collections.Generic.Stack`1.Pop() +76 Spe.Commands.Interactive.Messages.ShowMultiValuePromptMessage.ProcessResult(Boolean hasResult, String sig) +120 Spe.Commands.Interactive.Messages.BasePipelineMessageWithResult.Pipeline(ClientPipelineArgs args) +451

Regards, Ashok

ashokkarutur avatar Dec 07 '20 05:12 ashokkarutur

@ashokkarutur, just to confirm is this tested on a clean install of Sitecore? Removing any custom code out of the equation would be very helpful.

AlexKasaku avatar Dec 07 '20 09:12 AlexKasaku

@AlexKasaku Yes, this was reproducible by Sitecore support team as well "CS0195615"

ashokkarutur avatar Dec 07 '20 09:12 ashokkarutur

Looks like the code snippet was updated and anything custom has been removed @AlexKasaku @michaellwest so it should be possible to reproduce. Thanks so far!

hansdekker avatar Dec 08 '20 10:12 hansdekker

Definitely having some trouble consistently reproducing the issue. It happened for me once and then not again.

Can you confirm that the issue happens with this:

# Documentation : https://doc.sitecorepowershell.com/interfaces/interactive-dialogs
$options = [ordered]@{"OptionA"=1;"OptionB"=2;}
$optionTooltips = [ordered]@{1="Something interesting about A";2="Something interesting about B"}

$props = @{
    Parameters = @(
        @{Name="selectedOption"; Title="Choose an option"; Tooltip="Additional details about the option"; Options=$options; OptionTooltips=$optionTooltips; }
    )
    Title = "Option Selector"
    Icon = "OfficeWhite/32x32/question.png"
    Description = "Choose an option."
    Width = 450
    Height = 300
    ShowHints = $true
}

$result = Read-Variable @props
if($result -eq "cancel"){
    exit
}

michaellwest avatar Dec 12 '20 15:12 michaellwest

@michaellwest I was able to reproduce with this code.

https://www.screencast.com/t/sCtpogVcyp

ashokkarutur avatar Dec 12 '20 15:12 ashokkarutur

@michaellwest @AlexKasaku Can we provide you any further information or support?

hansdekker avatar Dec 17 '20 14:12 hansdekker

Does this issue happen between two different users from different computers? For example User A is running the wizard and User B is publishing.

michaellwest avatar Dec 17 '20 14:12 michaellwest

@michaellwest Yes this issue happen between two different users from different computers

ashokkarutur avatar Dec 17 '20 14:12 ashokkarutur

@michaellwest @AlexKasaku The issue is occurring when two publishers are working simultaneously, which explains why it's a problem. We need to be capable of multiple publishers working at the same time. Any ideas as to what might be causing this?

hansdekker avatar Dec 23 '20 12:12 hansdekker

Hi, I'm wondering if there is any more information I can provide for this, or how I can support a resolution.

happy newyear!

hansdekker avatar Dec 31 '20 11:12 hansdekker

Since the module is open source you are free to investigate the issue, make code changes to troubleshoot, and submit a PR to address the issue for the larger community. Unfortunately it's not immediately known on what the proper fix is.

michaellwest avatar Dec 31 '20 12:12 michaellwest

This seems to be SXA+SPE issue. There are SXA publish:end handlers that clear HttpRuntime cache and that affects SPE script session. Comment out/fix handlers below to address the issue

<handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.SitemapCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearSitemapCache" />
<handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.RobotsCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearRobotsCache" />

lillchic avatar Apr 27 '21 20:04 lillchic

This seems to be SXA+SPE issue. There are SXA publish:end handlers that clear HttpRuntime cache and that affects SPE script session. Comment out/fix handlers below to address the issue

<handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.SitemapCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearSitemapCache" />
<handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.RobotsCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearRobotsCache" />

Thank you @lillchic, Issue fixed :)

I have comment out the below handlers in "Sitecore.XA.Feature.SiteMetadata.config"

<events>
    <event name="publish:end">
        <handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.SitemapCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearSitemapCache" />
    </event>
    <event name="publish:end:remote">
        <handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.SitemapCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearSitemapCache" />
    </event>
    <event name="publish:end">
        <handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.RobotsCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearRobotsCache" />
    </event>
    <event name="publish:end:remote">
        <handler type="Sitecore.XA.Feature.SiteMetadata.EventHandlers.RobotsCacheClearer, Sitecore.XA.Feature.SiteMetadata" method="ClearRobotsCache" />
    </event>
</events>

ashokkarutur avatar Apr 28 '21 08:04 ashokkarutur