I am having a problem where my single call to .ajax is being repeated every 60 seconds until the remote side returns. As I write out my problem this way it makes me think of some kind of long-response call - but I have not done anything to set that up or request it.
My app runs on Linux, served by Apache and calls a CGI script hosted locally by the same Apache server. That CGI script makes a backend call and returns only after the backend call finishes. Lately that remote server has been occasionally taking many minutes instead of several seconds to return.
My webapp logging shows one call, and my Apache access_log shows that call repeating every 60 seconds. So I make a single GET request to the CGI script and the Apache log shows that request repeating every 60 seconds for however long it takes for the backend to return.
And because the cgi is getting called over and over again I have been making multiple requests to the remote service, which is very bad.
What is going on?
relevant javascript snippet
let call = {
callName: 'AddWithFulfillment',
cardholder: 'cardholderRecord',
cardholderHash: 'cardholderHash',
transactionNumber: 6206419,
};
console.log(new Date().toString(), 'call:', JSON.stringify(call));
$.ajax({
data: {
task: JSON.stringify(call)
},
url: '/cgi-bin/makeCall.sh',
dataType: 'json',
cache: false
}).then(
function success(data, textStatus, jqXHR) {
console.log(new Date().toString(), 'success:', JSON.stringify(data));
},
function fail(jqXHR, textStatus, errorThrown) {
console.log(new Date().toString(), 'fail:', errorThrown.message, JSON.stringify(data));
}
);
relevant bash script
#!/bin/bash
# extract the task from the query string into a workfile
q_str=$(echo -e ${QUERY_STRING//%/\\x} | sed 's/+/ /g')
task=$(echo "$q_str" | sed -n 's/^.*task=\([^&]*\).*$/\1/p' | sed "s/%20/ /g")
echo "${task}" > /tmp/workfile.txt
rm -f /tmp/workfile.result
touch /tmp/workfile.result
# wait for the result file, dump it into stdout & exit
while [[ 1 ]] ; do
if [[ -s /tmp/workfile.result ]] ; then
echo -e $(cat /tmp/workfile.result)
exit 0
fi
sleep 1
done
exit 1
representative console log
"Sun Oct 15 2017 13:13:56 GMT-0400 (EDT)" call: {"callName":"AddWithFulfillment","cardholder":" <...omitted...> ","transactionNumber":6206419}
"Sun Oct 15 2017 14:07:30 GMT-0400 (EDT)" success: {"callName":"AddWithFulfillment","cardholder":" <...omitted...> ","transactionNumber":6206419, "resultId": -1}
actual access_log
127.0.0.1 - - [15/Oct/2017:13:56:24 -0400] "GET /cgi-bin/logger.sh?txt1=%22calling.addWithFufilment+sending%3A%22%2C%22%7B%5C%22isProdCall%5C%22%3Atrue%2C%5C%22deviceAlias%5C%22%3A%5C%22JS-0589.1%5C%22%2C%5C%22callName%5C%22%3A%5C%22AddWithFulfillment%5C%22%2C%5C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%5C%22%3A6206419%7D%22&_=1508040892538 HTTP/1.1" 200 20 "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:13:56:24 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:13:57:24 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:13:58:24 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:13:59:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:00:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:01:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:02:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:03:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:04:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:05:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:06:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 - "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:07:25 -0400] "GET /cgi-bin/makeCall.sh?task=%7B%22isProdCall%22%3Atrue%2C%22deviceAlias%22%3A%22JS-0589.1%22%2C%22callName%22%3A%22AddWithFulfillment%22%2C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> TransactionNumber%22%3A6206419%7D&_=1508040892539 HTTP/1.1" 200 242 "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
127.0.0.1 - - [15/Oct/2017:14:07:30 -0400] "GET /cgi-bin/logger.sh?txt1=%22recording.addWithFufilment+params%22%2C%22%7B%5C%22isProdCall%5C%22%3Atrue%2C%5C%22deviceAlias%5C%22%3A%5C%22JS-0589.1%5C%22%2C%5C%22callName%5C%22%3A%5C%22AddWithFulfillment%5C%22%2C%5C%22cardholder%5C%22%3A%7B%5C%22 <...omitted...> resultId%5C%22%3A-1%2C%5C%22TransactionNumber%5C%22%3A6206419%7D%22&_=1508040897606 HTTP/1.1" 200 20 "http://localhost/enrollment/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"