I have a very simple piece of code written in node.js (see below example) which runs on Kubernetes on GCP and AWS. The app just does GET request to import data from an external application. Sometimes that GET request could take ~30 mins or more.
var http = require("http");
var request = require('request');
var options = {
url: "my-external-service",
gzip: true,
// (1) forever: true,
// (2) agent: new http.Agent({ keepAlive: true })
};
request.get(options, (error, response, body) => {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
The problem is that my node.js app never receives the response even if it was returned by the external service. It seems that the connection was dropped somewhere between the node app and external service.
I've tried to use:
forever: true
optionIt didn't help. My node application would run forever if I don't use the timeout
option. When timeout
is set and exceeded I got ESOCKETTIMEDOUT
error.
What is interesting:
Is it posiible Kubernetes drops my connection? And why? How does CURL set the keepalive settings and why CURL request work from Kubernetes?
PS. Instead of request.js, I tried to use other libs like node-fetch or axios but results were the same.