Scriptrunner script hanging up Issue Viewing

Khanh Nguyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 18, 2015

We are running on. . .

JIRA v6.3.15

scriptrunner v3.1.4

When this scripted field script below runs (sometimes taking a few minutes to complete), the issue viewing (view screen) by other users are spinning.  As soon as this script fininshes, those spinning issue views will refresh soon after.

Why is this script/thread stalling the Issue viewing by other users.  A point to note is that while this script runs, Dashboards will refresh just fine without delay.  It seems to only effect issue viewing (unsure about other functions).

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import java.text.*
import java.util.*
import java.text.SimpleDateFormat
import org.apache.log4j.Category
// Logger
def Category log = Category.getInstance("com.onresolve.jira.groovy.zzz_Get_History_For_Issue")
def changeLoop = 0
def historyLoop = 0
def historyItemLoop = 0
// Set the logging level to INFO
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "checking $issue ${issue.getClass()} ${issue.getResolution()}"
if(issue.resolutionDate){
	log.info "issue is completed $issue.resolution"
	//This script is used by a Scripted Field that is used by XPorter in the PDFS to display an issues History
	ComponentManager componentManager = ComponentManager.getInstance()
	log.info "Starting zzz Get History for Issue Script for $issue.key"
	def changeHistoryManager = componentManager.getChangeHistoryManager()
	def SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm")
	def changehistoryItems = changeHistoryManager.getAllChangeItems(issue);
	def StringBuffer html = new StringBuffer()
	html.append "Issue $issue.key ChangeLog Items\n"
	changehistoryItems.each{ historyItem ->
		def creationDate = formatter.format((java.util.Date)historyItem.created)
              historyItemLoop++
              log.info "## in change history item loop $historyItemLoop time(s)##"
		if (historyItem.field =="status") {
			def from =  historyItem.froms.toString()
			def to  =  historyItem.tos.toString()
			html.append "\n$creationDate -  Status Changed From: $from To: $to by $historyItem.user."
		} else if (historyItem.field!="status") {
			def changehistories = changeHistoryManager.getChangeHistories(issue)
			changehistories.each() { changeHistory ->
				def changeitems = changeHistory.getChangeItemBeans()
                
                historyLoop++
                log.info "## in change history loop $historyLoop time(s)##"
				changeitems.each(){ changeItem ->
                    
                    changeLoop++
                    log.info "## in change items loop $changeLoop time(s)##"
					if(changeItem.field == historyItem.field && changeItem.created == historyItem.created){
						fromValue = changeItem.fromString
						toValue = changeItem.toString
						if (fromValue && fromValue.contains("<br>")){
							fromValue = fromValue.replaceAll("<br>","\n").replaceAll("<div>","").replaceAll("</div>","");
						}
						if (toValue && toValue.contains("<br>")){
							toValue = toValue.replaceAll("<br>","\n").replaceAll("<div>","").replaceAll("</div>","");
						}
						html.append "\n$creationDate  -  $historyItem.user changed $historyItem.field FROM $fromValue TO $toValue."
					}
				}
			}
			html.append "\n"	
		}
	
	}
log.info "Ending zzz Get History for Issue Script for $issue.key"
html.toString()
}

Note that I have debug/info log statements in there for troubleshooting purposes.

My question is why is this script (when executing) seems to stall all Issue viewing in the JIRA Instance?  Is there a way to for the script to use a different thread perhaps to avoid conflicting with the thread that's used for issue viewing?

 

Thanks in advance for your help!

 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Jeff Louwerse
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2016

Hi Jamie,  I am having what seems like the same issue in that any script I run seems to lock issue viewing or editing.  one of the simplest scripts (run as a service)  I have has to reindex issue nightly but if I try to view an issue, or edit and issue the interface will not return anything until the script is done.   The weird part to me is that if I run the built in script to reindex issues, it doesn't lock JIRA up. 

as best I can tell this is almost exactly the same as your canned script which doesn't lock it up..  I thought perhaps it was the reindex part but commenting everything but the log message had no effect.  it still locks up an issue view/edit until complete.

This is just an example but it seems to apply to any script I run.. either as a script, file or service.

JIRA 6.4.11 and Script Runner 3.1.4

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.crowd.embedded.api.User
import org.apache.log4j.Level
import org.apache.log4j.Logger

Logger log = Logger.getLogger("service.reindex_CAR");
log.setLevel ( Level.DEBUG );

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
IssueIndexManager indexManager = ComponentAccessor.getIssueIndexManager();
User myUser = ComponentAccessor.getUserUtil().getUserObject('automation');

String jqlQuery = "project=\"CAR\" and Resolution = \"Unresolved\" ";
SearchService.ParseResult parseResult = searchService.parseQuery(myUser, jqlQuery);
SearchResults results = searchService.search(myUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
List issues2index = results.getIssues();
for ( Issue issue in issues2index )
{   boolean wasIndexing = ImportUtils.isIndexIssues();
    ImportUtils.setIndexIssues(true);
    log.debug("Reindex issue ${issue.key}")
    indexManager.reIndex(issue);
    ImportUtils.setIndexIssues(wasIndexing);
}

def myOutput = ["output": "${issues2index.size()} issues were reindexed "]
log.info myOutput
myOutput

 

 

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2016

So you're saying any script that you run locks JIRA up for others? That doesn't make any sense to me.

Why do you want to reindex the issues on a service?

 

Jeff Louwerse
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2016

Sorry for the last response, been dealing with a JIRA Agile.

It doesn't make any sense to me either and it not something I had ever noticed before and I have done complete migrations using a custom importer I built that ran for days.  If this is not normal in JIRA 6 and there is nothing obvious in my code I have to assume it is something with my server so I will dig into that.  That is where I was going when I saw this question. 

In my example I simply picked the easiest one I had and one I can confim does not lock up issue view/edit when I run the built in script.  It really doesn't matter what the script is, I have replaced the reindex part with sleep(200) and it did the same thing.  The reason for this particular service is that  I reindex one projects open issues nightly in order to index a calculated field "days Overdue".  It is only a handful of issues and completes in 10 seconds or less.. just long enough for me to test but not so long I will get tickets from the end users.. 

My main concern is that I have a lot of other maintenance/utilities scripts that can run longer.   sometimes I might have to create/update/reindex 1000s of issues.

 

 

 

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2016

You need a thread dump when it's hanging.

If the built-in script doesn't have a problem you can run it via a service, it's similar to https://gist.github.com/jechlin/7198215. Except that the two possible parameters are FIELD_FILTER_ID and FIELD_PROJECT_ID, use one or the other of them. Also you don't need the thread stuff in a service.

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

Can you get a thread dump when it's hung? I ran your script with a couple of modifications: https://gist.github.com/jechlin/408b4ad91d0bbb3017c6 - and added it to the issue navigator so I ran it for many issues concurrently and didn't have a problem.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

I would try with the code I posted. Because you have omitted the "def" from fromValue and toValue you are putting that in the script binding, maybe it has greater scope than you are expecting and is causing a problem.

Chris Solgat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

I have some thread dumps from when it was happening. Let me know where you want me to send them. Also, I just noticed that when it's running an http-bio-####-exec thread, it is putting all of the other http-bio threads into Park status. A test issue that we are working with, the total of the Changelog History (after the script has processed and placed the value into the field) is 290,474 characters. The Description field is 78,097 characters. We only see this problem when the change history is very long. To be specific, I think the Description field was updated a total of 3 times after issue creation.

Khanh Nguyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

Hi Jamie, Both Chris and I are working this jointly. The problem we have is that since this scripted field will run long on issues with gigantic size Description and Comments. These can run 1 to 5 minutes in some cases. It seems that since the upgrade of Jira 6.3 and Scriptrunner 3.0.16, when this scripted field is executing, the viewing of issues by other users are stalled until the execution of this script completes. It sounds similar to GRY-592, but we have upgraded our test environment to it and the problem persisted. Why does issue viewing get stalled while this scripted field runs. ALSO, dashboards will display and refesh just fine while this this scripted field executes. Thanks in advance for your time.

Khanh Nguyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

GRV-592 not GRY-592

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

it's great that you're working on it together, but if you both ask the same question it forces me to duplicate a lot of work. If the stack trace is confidential you can create a support request at https://productsupport.adaptavist.com/servicedesk/customer/portal/2

Khanh Nguyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 21, 2015

Quick question. . . does Scripted Fields persist anything in the Jira DB? Or does the result of the Scripted field all dynamic for viewing/displaying on screen and nothing is persisted? Thanks.

TAGS
AUG Leaders

Atlassian Community Events