Duplicated request HTTP IN node

Hi all, I need your help.
I noticed with the http in and http response node that when the request goes in timeout the request is duplicated more time so I have many error.
I search on the forum and on google, I saw other people with this problem but I not found a solution.
I would to increase a few the timeout, but if it is not possible I would at least to avoid the creation of the duplicate request after the timeout.
Do you know a way to fix this problem?

A screenshot is a thousand words :wink:

very little information to understand how your flow is setup.
So you have an Http in that then does a Http request ?

Can you share a flow and paste a few messages of the timeout errors that your getting ?

You can configure the Http request timeout with

image

Thanks for the answer.
I know that I'm not good to write in english, sorry.

Yes I have an HTTP IN at the start and an HTTP Response at the end. In the middle I have HTTP request nodes but it is not the problem, I made test only with a delay node and the problem is the same.
I call the flow in a browser page by a normal ajax request. The script on the page is very simple, is only one call on button click, there isn't for or while cycle.
If the flow returns a response in 120 seconds there is no problem but if the flow gives a response in more than 120 seconds a new duplicate requests are created but the first flow continue to work.
This is a probem of the browser settings or of nodered settings, i don't understand.
I tried with the httpRequestTimeout but it seems doesn't resolve the problem
This is my flow

sorry i dont have any experience in this field but ...
have you tried also setting a Timeout on you jquery? ajax request ?

$.ajax({
    url: "test.html",
    error: function(){
        // will fire when timeout is reached
    },
    success: function(){
        //do something
    },
    timeout: 3000 // sets timeout to 3 seconds
});

credit to stackoverflow post

Yes I extended the timeout in the javascript but the behaviour didn't change

Just to clarify .. when you say

where exactly do you see that ? in the http in node ?
did you put Debug nodes at every step of your flow to pinpoint where that duplicate request is coming from ?

I doubt that its from the Http in node since as you said its only triggered by ajax with the click of a button and especially since you increased your timeout. So something else is triggering them. Folllow the flow of messages with debug nodes.

Thanks UnborN.
Ok, I made a simple flow to make simple the debug.
This is a simple flow to print Hello, there is also a debug message to print the payload


and this is the code

[{"id":"78837dc5.9f1bc4","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"cd8e7607.ff6ad8","type":"http in","z":"78837dc5.9f1bc4","name":"","url":"/hello","method":"get","upload":false,"swaggerDoc":"","x":250,"y":180,"wires":[["f4b51600.10f908"]]},{"id":"9920375b.19d29","type":"http response","z":"78837dc5.9f1bc4","name":"","statusCode":"200","headers":{},"x":820,"y":400,"wires":[]},{"id":"f4b51600.10f908","type":"change","z":"78837dc5.9f1bc4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":240,"wires":[["c73aabf5.8f75b"]]},{"id":"c73aabf5.8f75b","type":"template","z":"78837dc5.9f1bc4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload}} !","output":"str","x":600,"y":300,"wires":[["dc4db2d7.25fbf","9920375b.19d29"]]},{"id":"dc4db2d7.25fbf","type":"debug","z":"78837dc5.9f1bc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":260,"wires":[]}]

This is a simple web page to call the flow by a button

<!doctype html>
<html>
	<head>
		<title>Test</title>
		<meta charset="UTF-8"> 
		<script>
			function loadDoc(){
				var xhttp = new XMLHttpRequest();
				xhttp.timeout = 600000;
				xhttp.onreadystatechange = function() {
					if (this.readyState == 4 && this.status == 200) {
						document.getElementById("demo").innerHTML = this.responseText;
					}
				};
				xhttp.open("GET", "http://localhost:1880/hello", true);
				xhttp.send();
			}
		</script>
	</head>
	<body>
		<section>
			<form id="mail_form" name="mail_form" novalidate="novalidate">
				<fieldset>
						<div class="controls">
							<button class="btn btn-success" type="button" onclick="loadDoc()">Send</button>
						</div>
				</fieldset>
			</form>
		</section>
		<section>
			<p id="demo"></p>
		</section>
	</body> 
</html>

Now when I click on the button in the web page I receive the response immediately so the page writes the payload message in a paragraph and on node-red in the debug panel we can see the payload message once time.

Now this is the same flow with a delay of 120 seconds to simulate a slow elaboration.

[{"id":"78837dc5.9f1bc4","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"cd8e7607.ff6ad8","type":"http in","z":"78837dc5.9f1bc4","name":"","url":"/hello","method":"get","upload":false,"swaggerDoc":"","x":250,"y":180,"wires":[["f4b51600.10f908"]]},{"id":"9920375b.19d29","type":"http response","z":"78837dc5.9f1bc4","name":"","statusCode":"200","headers":{},"x":860,"y":420,"wires":[]},{"id":"f4b51600.10f908","type":"change","z":"78837dc5.9f1bc4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"hello","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":240,"wires":[["c73aabf5.8f75b"]]},{"id":"c73aabf5.8f75b","type":"template","z":"78837dc5.9f1bc4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload}} !","output":"str","x":600,"y":300,"wires":[["dc4db2d7.25fbf","80401b0a.b9ff08"]]},{"id":"dc4db2d7.25fbf","type":"debug","z":"78837dc5.9f1bc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":260,"wires":[]},{"id":"80401b0a.b9ff08","type":"delay","z":"78837dc5.9f1bc4","name":"","pauseType":"delay","timeout":"120","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":740,"y":360,"wires":[["9920375b.19d29"]]}]

I inserted the delay after the debug message so when I call the flow by the button in my web page I can see immediately the message in debug panel but not in the web page because is present the delay, so I wait for 120 seconds an now there is the problem. After this 120 seconds in the debug panel another message appears, and a new message appears in the debug panel each 120 seconds without ending.

It seems that after 120 seconds nodered restart the flow until it return a response in less than 120 seconds. Or maybe the browser recall the flow after 120 seconds though there isn't cycle in the javascript and the timeout is setted to 600 seconds.
For me is important to block these repeated calls, it's better if I can to extend the timeout but if it is not possible I need to don't restart the flow when I don't receive the response

This is the debug panel after the call with the delay
Immagine4

Strange .. i get the same with you with your test flow.

i tried a banch of tests with Postman and trying different request headers
I even changed in the .node-red folder in settings.js these lines that seem to be related but with no luck

 // Timeout in milliseconds for TCP server socket connections
    //  defaults to no timeout
    socketTimeout: 150000,

    // Maximum number of messages to wait in queue while attempting to connect to TCP socket
    //  defaults to 1000
    //tcpMsgQueueSize: 2000,

    // Timeout in milliseconds for HTTP request connections
    //  defaults to 120 seconds
    httpRequestTimeout: 150000,

Yes I also tried this option but they don't resolve the problem.
And I noticed that the repeated requests are not infinite but they stop after 5 requests.
But I didn't find the 5 numbers in any options in settings.js

In the case of a GET request, that you are visiting an endpoint with the browser, like the 'hello' test flow you sent ... i believe its the browser that is doing the multiple (5) requests.
because with Postman i get only one.

yea .. it seems that the httpRequestTimeout setting doesnt apply for the Http In node.

Hi @NoSuchException

I was researching a little bit more on the timeout settings and i may have found a workaround.
In the settings.js file you can un-comment the lines relating to node red's middleware which basically is a piece of code that executes on each request on the underlying express server of node-red. That includes the Http-In node.

// The following property can be used to add a custom middleware function
    // in front of all http in nodes. This allows custom authentication to be
    // applied to all http in nodes, or any other sort of common request processing.
    httpNodeMiddleware: function(req,res,next) {
       // Handle/reject the request, or pass it on to the http in node by calling next();
       // Optionally skip our rawBodyParser by setting this to true;
       //req.skipRawBodyParser = true;
       req.setTimeout(130 * 1000);
       next();
    },

I've set it to 130 seconds and your 'hello' test flow with the 120 seconds delay doesnt timeout and receives a reply. Now i dont know if this is good practice and possibly there are better ways to keeping a connection open for so long. maybe looking into websockets

Hi UnborN,
you are great
thank you very much.

Your workaround work fine also with my main project.
Yes it is not the best solution because if a request requires more time that the new timeout the problem with the duplicate requests is present again, but I'll try to set a timeout of the slowest requests that I saw.

So this problem is resolved for me.
Thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.