HTTP request timeout and content download time - javascript

I'm having a weird issue about HTTP requests...
The request is marked as "Pending" under the network and eventually a timeout happens. The timing tab shows this
The weird thing about this is that if I execute the exact, same HTTP request a second time it gets processed in 500ms and I correctly get the requested data.
Does someone know how this can happen and how can this be fixed?
Thank you!!

For those who are still looking for this, it happened that due to a coding error AngularJS started to trigger a huge amount of digests that blocked the client to get the HTTP response.

Related

Nest.js long requests are blocked by CORS and return null

I have an endpoint in a Nest.js controller that receives a post request with an excel file and have to do an operation that takes a lot of time over that excel, the problem is that every request that takes more than one minute (60000 ms), returns null. The most confusing thing is that is not even throwing timeout error, the process in the server runs correctly under the hood, but in the front i'm receiving a CORS block error.
Something like this.
Access to XMLHttpRequest at 'https://api-asd.com/endpoint/upload-excel' from origin
'http://asd.com.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin'
header is present on the requested resource.
When i want to process the response i can't because i receive null in the front. I tried setting the timeout of nest.js server to three minutes but still doesn't work. Also tried checking the timeout in client side, but axios default timeout is 0 and i didn't changed it, so it should wait until the request is finished.
CORS is enabled and it works perfectly if the operations lasts less than one minute. Even checked if the file limit was blocking the upload, but in the back-end the file is received and the process runs anyway.
It is possible to solve this problem?
Note: I'm using next.js in the front.

Handling get response while server has been crashed

I have a question.
I send a Get request by Ajax every second and expect to get some response from the server.
In the case and my application crashes and I continue to send Get request every second, I don't get any response until receiving the server's timeout error (an error code 502.) .
If somebody knows how I can handle this moment between sending the get requests every second and until receiving error code 502.
Thanks
If the server is down, whatever you are using for the ajax call should have errored out... in which case you should handle it with a call back or a catch block. There, you should handle what you will do on the frontend based on the response.
As far as not sending out more requests, there really is no way to know for sure. For all your code knows, the server is particularly slow at that moment.

Browser mangling 302 responses from Ajax requests

I have the following.
AJAX request made to server from mydomain.blah.com
Server returns 302 but to a slight different domain blah.com not mydomain.blah.com
Browser appears to mangle response. Instead of the 302 coming into my error callback a response with no response body and no status code is returned.
Further details
Looking at request in IE 10 it is marked as aborted.
In FF , firebug shows the 302 coming back but it never been handled.
To complicate matters (although I don't this is relevant) there are multiple ajax requests sent over.
The reason why the 302 is returned is because my server session is timed out and I am being redirected to a login page. I don't have much control over the server.
I want to get the response code 302 sent from my server into my error callback. This is what I want to achieve.
The ajax calls are being made using JQuery.
Any help appreciated.
If it is offical policy for browsers to "mangle" 302 responses to difference domains from ajax calls then if anyone could provide a reference that would be cool. Then I'd know there is not much I can do about this.

Is there a definitive way to determine whether an XHR request was user-aborted

I'm trying to determine whether an XHR request (sent via Dojo) failed due to the user requesting a new page, or whether it's a true failure.
There's a nice try here, but it would also catch the situation whereby the server that is receiving the request fails to respond due to a server error.
One thing that occurred to me is that I could check to see if the page is currently unloading, but I don't know if that's a state that can be queried, without implementing it some way.
Any thoughts?

Performing GET request before leaving page

If a GET request is made as follows
$(window).bind('beforeunload', function() {
// GET request
});
and the page is abandoned before the GET request is completed,
will the destination server still process the request? Or will it somehow vanish?
I would like to send a server data on beforeunload firing, but without stealing useless ms from the user.
It would be very useful if someone could help me.
If it is an asynchronous request then the server may process it (if it receives the request) but I don't know if you can guarantee that the request will go through before the page is unloaded or if it will be processed - this may depend on the actual web server (someone else may have more information). If you make a synchronous request, the page will wait until the request goes through and it gets back a response (so in this case, processing is guaranteed). However, this means that your browser will be locked up until that request completes, which may not be desirable.
In most cases yes, but it depends on the web application server. Some can detect the disconnect and stop with the request.

Categories

Resources