When handling XMLHttpRequest in Nodejs proxy server, I've already call "res.end()", but client's behavior seems can't get my res and timeout finally - node.js

I have a question.
In my Nodejs proxy server, from debug log, I can see I've already handled the request, send its correct response and call "res.end()" to end this request. And this request is XMLHttpRequest.
And from Chrome's developer tool, I can see that this request has got correct response from my Nodejs https server, and its status code is 200 OK.
But from the web UI, the client seems still waiting for my response because its image is always turning over and over, and seems to time out finally. Like the screenshot below.
Can anyone give me some advice? I don't understand why the client can't get my response data. And this request is XMLHttpRequest.Thanks very much.

I've found the answer. Because I need to response to long poll request immediately. If don't, the client will cancle the request or timeout

Related

I'm experiencing a long response time in posting data in postman api

When I send a request in postman api, the application freezes or is stuck on the Sending Request screen.And it is unable to post data.
Can anyone helps me to solve this issue.
Thanks in advance
This can happen if you are debugging your nodejs server and it's caught on a breakpoint. If so, the response will hang. To fix it, just disable that breakpoint, restart your nodejs server, and issue the request again with Postman.

Unexpected delay in API response time on Node server

I am working on a chat bot which uses node as its backend server. So, to respond back to user's query, I have to make some other api call which are taking long to respond which causes delay in providing response to the user.
My problem is whenever i call a third-party api from node server it's response time is around 500-900ms whereas Postman gives back the same response in 80-120ms.
I have tried using following modules, but all of them give almost same response time:
request
axios
https
How to achieve the same response time which i am getting in the Postman?

Why Chrome Refreshes the URL after certain minutes of receiving no response?

In my node application I have an anchor tag which when clicked will request an Express GET route which makes some API calls and render the response in an EJS template.
When the API being requested from Express route takes too long to respond, the Node express route URL gets requested again automatically.
Can anyone explain this behaviour ?
In HTTP/1.1 Connections:
8.2.4 Client Behavior if Server Prematurely Closes Connection:
If an HTTP/1.1 client sends a request which includes a request body,
but which does not include an Expect request-header field with the
"100-continue" expectation, and if the client is not directly
connected to an HTTP/1.1 origin server, and if the client sees the
connection close before receiving any status from the server, the
client SHOULD retry the request
Browsers mostly will re-try a connecton until a proper response is given, on Chrome i believe it's 5 attempts.
It's a expected behavior.
There's a nice article from Oracle's blog that has a similar scenario described.

Heroku H12 Timeout Error with Node.js

Currently, I am working on a REST API using the Node hapijs framework. The API is deployed on Heroku.
There is a GET endpoint in the API that makes a get request to retrieve data from a third party and processes the data before sending a reply. This particular endpoint times out from time to time. When the endpoint times out, Heroku returns an H12 error. Once it has timed out, subsequent requests to that endpoint result in the H12 errors. I have to restart the application on Heroku to get that endpoint working again. No other endpoints in the API are affected in any way by this error and continue to work just fine even after the error has ocurred.
In my debugging process and looking through the logs, it seems that there are times when a response is not returned from the third party API, causing the error.
I've tried the following solutions to try and solve the problem:
I am using the request library to make requests. Hence, I've tried setting a timeout to 5000 ms as part of the options passed in to the request. It has worked at times... the timeout is triggered and the endpoint sends the timeout error associated with request. This is the kind of behavior that I would like, since subsequent requests to the endpoint work. However, there are times when the request timeout is not triggered but Heroku still returns an H12 error (always after 30 seconds, the Heroku default). After that, subsequent requests to that endpoint return the H12 error (also after 30 seconds). It seems that some sort of process gets "stuck" on Heroku and is not terminated until I restart the app.
I've tried adding a timeout to the hapi.js route config object. I get the same results as above.
I've continued doing research and suspect that the issues has to do with the description given here and here. It seems like setting a timeout at the app server level that can send a SIGKILL to the Heroku worker might do the trick. It seems fairly straightforward in Ruby but I cannot find much information on how to do this in Node.
Any insight is greatly appreciated. I am aware that a timeout might occur when making a request to a third party. That is not the issue. The issue is that the endpoint seems to get "stuck" on Heroku after a timeout and it becomes unresponsive.
Thanks for the help!
I had a similar issue and after giving up for a day, I came back to it and found my error. I wasn't sending a response to the client when an error occurred on the server side. Make sure you are returning a response no matter what the result of your server side algorithm is. If there is an error, return that. If the request was successful, return that response. I hope that helps.
If that doesn't help, check heroku's guides on handling Request Timeouts, especially the Debugging request timeouts section could be of help:

How can I abort a request sent using wininet?

I have an MFC application in which I used to send a post request to the corresponding server.
It is an http request, for uploading a file.
But there is a requirement to abort the request sent. Like if the user is sending a large file and user should be able to cancel the request before it is completed.
I am using wininet apis,
HttpSendRequestEx, InternetWriteFile and HttpEndRequest for this.
but once the request is sent, I am not able to abort it in between unless the request is got completed or timed out.
Anyone please suggest an option for canceling a processing or sent request.
I have tried closing the request handles, but still the request not gets aborted.
Any one please help..
Thanks in Advance
From a client aspect, you can only abort/disconnect from the current operation by using the InternetCloseHandle routine.
This will instantly abort the request/operation from a client perspective, so the user can continue with another action.
But when the data has already been sent to the server, this will only result in not getting back a response!
As said by Igor, you cannot abort the processing at the server, as soon as the complete request (data) has been sent (at which point the client just waits to receive data from the server).
So you need to look at the point where you want to cancel 'sending' the request or revert the file addition at the server by sending a new 'delete' request from the client to the server, using the response of the first request (this response should contain information about the added file - like a key).

Resources