Kubernetes drops long HTTP GET connection initialized in node.js

5/14/2018

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:

  1. request.js's forever: true option
  2. setting keepAlive agent

It 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:

  • the same code works perfectly fine on my local machine
  • it also works fine on Linux virtual machine which works behind NAT
  • works fine from Kubernetes machine when I repeat the request using CURL

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.

-- ramlez
google-cloud-platform
http-get
kubernetes
node.js
requestjs

0 Answers