503 Service Unavailable

I'm getting an error quite often now when working with the API. (503 Service Unavailable)

It seems to happen more often when doing batch functions or other repeated calls. Is anyone else having this issue?

Thanks for this @Robert.

Of course, there's the same issue with Zapier too.  However, this seems to be getting worse. I wonder if server resources need improving @knack hmmm. Actually causing me a lot of grief.

Super helpful 397252071171 thanks for sharing.

Posted this on another thread but I hope it helps someone:

When making any Ajax request, the server may randomly throw a 503 Bad Gateway or 429 Too Many Requests error. When that happens, we need to retry the Ajax request. However, since the issue is server-side, we also need our Ajax request to wait until the server issue is resolved. This solution takes that into consideration by using setTimeout to wait before trying to send the Ajax request again and then increases the interval of time to wait after each failure:

$.ajax({
url: URL, // variable name, insert URL here
type: "GET",
headers: {
"X-Knack-Application-Id": Knack.application_id,
"X-Knack-REST-API-Key": `knack`,
"Authorization": Knack.getUserToken()
},
tryCount: 0,
retryLimit: 3,
async: false, // optional but nifty
success: function(data) {
// your success code!
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
this.tryCount++;
let tryCount = this.tryCount, retryLimit = this.retryLimit, seconds;
if (tryCount <= retryLimit) { // then try again
switch(tryCount) {
case 1:
case 2: seconds = 5; break;
case 3: seconds = 10; break; }
let timeout = seconds * 1000;
console.log("Error: " + XMLHttpRequest.status + " " + XMLHttpRequest.statusText + "\nRetry Count: " + tryCount + "\nRetrying in " + seconds + " seconds")
let ajaxObject = this;
window.setTimeout(function(){
$.ajax(ajaxObject);
}, timeout);
return;
} else {
// Routine above failed. Insert error message or something here.
// I typically use alert("something") then window.history.back();
}
return;
}
});

Note: Using the switch table, you can customize the interval of time (increase/decrease) for each retry iteration. You can also customize the number of retries attempted in retryLimit. Do what makes sense for your API Limit. I've tried multiple interval settings. My fastest retry success time was 5 seconds. My slowest retry success was 17 seconds. Thus my intervals span a total of 20 seconds to cover all bases.

Also getting a 503 error this time via Zapier actually same thing though the API.

I first reported this 503 error in Sept 2019. At that time I was getting tons of of them. (maybe 50% of API calls in a batch recipe were getting the 503 error) They did something in mid September around latency that seemed to resolve the issue for a bit. Since that time it's been closer to 10% error rate from what I can tell. 

I created a new support request in early December, but that continues to remain open with no resolution. 

I received the same response over a week ago. Followed up yesterday and was told they were working with the technical team to track down the cause. I will post here if they come back with a solution.

Is anyone getting a response from knack on this?  Last response I received last week is we're aware of, looking into it, and will get back to you.  Asked for an update but nothing but crickets on their end.

I'm catching 503s and retrying 3 times with a backoff of an extra second each retry, but it doesn't seem to be making a difference.

Totally agree with Tony on this - error checking for all Ajax calls trapping 503s mandatory in our apps now.

Similar to 429 errors here https://support.knack.com/hc/en-us/community/posts/360019050751-Throttling-API-calls-and-preventing-429-error and the original Stackoverflow reference here https://stackoverflow.com/questions/10024469/whats-the-best-way-to-retry-an-ajax-request-on-failure-using-jquery

Ditto, getting it as well.  Ticket submitted regarding this

 

Experiencing intermittent 503 errors also with calls to the API.

I get it all the time I have simply by default coded in error checking for all API calls that waits 5 seconds and tries again it will do it up to 5 times before it freezes its state and sends me a notification for manually checking it. I have got it running pretty smooth now that I have redundant error checking across all the systems. Many times on write actions it gets written just doesn't' return anything or 503 then when i check it the data is there and i move on.

@RobertHill Thanks for your response to this thread above. One question - this code fragment shows a GET call, but can you also do this for a PUT call to update a record? I’m trying to implement a retries mechanism with the ky library, and when the 503 gets returned for the OPTIONS pre-flight request, retries are not happening.

Good question and, in short, yes!

Here is a View-Based AJAX PUT example piece of code that I use to capture the data.id of a record and put it into “field_667” on a form that contains that field. It retires three times. I haven’t seen it fail yet. However you can add an absurdly large number of retry attempts. You could also set up a task to notify you when things go awry to alert you that a manual entry is needed:

$(document).on('knack-record-create.view_638', function(event, view, data) {
	Knack.showSpinner();
	const recordID = data.id;
		$.ajax({
		url: "https://api.knack.com/v1/pages/scene_238/views/view_2732/records/" + recordID, // This is the View/Form for Capturing Record ID
		type: "PUT", 
		headers: {
			"X-Knack-Application-Id": Knack.application_id,
			"X-Knack-REST-API-Key": `knack`,
			"Authorization": Knack.getUserToken()
		},
		data: {field_667: recordID,}, // Field Used for PUT Request. MUST BE ON FORM USED IN URL ABOVE.
		tryCount: 0,
		retryLimit: 3, // Increase/decrease as desired
		success: function(response) {
			console.log("Captured Request ID"); // Success Message in Console Log Or Insert Custom Routine Here
			Knack.hideSpinner();
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			this.tryCount++;
			let tryCount = this.tryCount, retryLimit = this.retryLimit, seconds; 
			if (tryCount <= retryLimit) { //try again
				switch(tryCount) {
					case 1:
					case 2: seconds = 5; break;
					case 3: seconds = 10; break; 
					default: seconds = 5; break;} // If above third retry attempt, defaults to 5 seconds
				let timeout = seconds * 1000;
				console.log("Error: " + XMLHttpRequest.status + " " + XMLHttpRequest.statusText + "\nRetry Count: " + tryCount + "\nRetrying in " + seconds + " seconds")
				let ajaxObject = this;
				window.setTimeout(function(){
					$.ajax(ajaxObject);
				}, timeout);
			} else {
				console.log("Failed to Capture Request ID"); // Or Insert Custom Routine Here
			}
		}
	});
});
1 Like

@RobertHill Thanks! I ended up implementing wretch (thanks to @hmnd !) for all API calls, which has a built-in retries capability. It’s working great.