This is a long shot but here goes...
I'm using Scriptrunner to integrate between Jira and various other applications via their REST APIs and using the built-in Unirest library. I've got dozens of scripts that do this and work just fine.
I'm having problems with one application however. In a GET call, it will randomly return a 503 (Service not available) response and I'm having trouble handling it. It feels like Unirest is trying to catch/handle this response by retrying the request automatically instead of letting my script handle the response. The end result is that my script is timing out and failing. Hoping for some insight into how to deal with this.
Here's the fragment of my script that makes the call.
def post(def hostUrl, def endpointAndQuery, def bodyJson, String authString) {
def maxTries = 3
def tryCount = 0
while (tryCount < maxTries) {
logger.info("BHR Post try: ${tryCount}")
try {
def result = post("$hostUrl$endpointAndQuery")
.header('Accept', 'application/json')
.header('Content-Type', 'application/json')
.header('Authorization', authString)
.body(bodyJson)
.asObject(Map)
if (result.status == 200){
logger.info("BHR Post good result")
return result.body
} else if (result.status == 503) {
logger.warn("BHR 503 response")
sleep(5000)
} else {
logger.info("Error: Status: ${result.status} ${result.body}")
return null
}
} catch(Exception e1){
logger.error("Exception in BHR: ${e1}")
}
sleep(2000)
tryCount++
}
}
Here is the section of the Scriptrunner logs when the 503 happens
2025-03-28 11:47:55.604 INFO - BHR Post try: 0 2025-03-28 11:47:55.845 INFO - Serializing object into 'interface java.util.Map' 2025-03-28 11:47:55.846 INFO - POST https://api.bamboohr.com/api/gateway.php/smarsh/v1/reports/custom/ asObject Request Duration: 240ms 2025-03-28 11:47:55.847 WARN - POST request to https://api.bamboohr.com/api/gateway.php/smarsh/v1/reports/custom/ returned an error code: 503, retrying in 300s... 2025-03-28 11:51:54.554 ERROR - Failed to wait 300s before retrying the request 2025-03-28 11:51:59.006 INFO - Serializing object into 'interface java.util.Map' 2025-03-28 11:51:59.042 INFO - BHR Post good result
As you can see, I get a 503 with a message saying retrying in 300 seconds and then, just under 4 minutes later, I get told I failed to wait 300s before retrying and apparently fall through to the 200 response test and print "BHR Post good result".
At this point, Scriptrunner says I've been running too long and gives me an error email saying the script timed out after 240 seconds.
I'm struggling with what to do here. I know there are advanced options for Unirest but I'm not clear if the version in Scriptrunner supports them (from a previous support call with them, I know this is not the full package).
Any insight would be appreciated
Hi @Tom Hudgins
From the error you are receiving it indicates that the Service is Unavailable.
Are you able to do a basic CURL request to the destination URL to see if it is able establish connection?
Thank you and Kind regards,
Ram
I apparently didn't describe this clearly enough.
The call works most of the time so it's not a question of whether I can do this with CURL.
The problem is that sometimes (randomly - I can't reproduce it reliably) the service returns the 503 response and I need to be able to handle it and retry without my scriptrunner script timing out.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.