From ff042d8c1fc95606eb317f75702f248e114b467f Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Sat, 18 Apr 2020 23:07:55 +0300 Subject: [PATCH] Do not timeout watch requests Signed-off-by: Lauri Nevala --- patches/http-proxy+1.17.0.patch | 22 ++++++++++++++++++++++ src/main/context-handler.ts | 9 ++++++--- src/main/proxy.ts | 3 ++- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 patches/http-proxy+1.17.0.patch diff --git a/patches/http-proxy+1.17.0.patch b/patches/http-proxy+1.17.0.patch new file mode 100644 index 0000000000..ded714afc4 --- /dev/null +++ b/patches/http-proxy+1.17.0.patch @@ -0,0 +1,22 @@ +diff --git a/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js b/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js +index 995a0db..a5c37f5 100644 +--- a/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js ++++ b/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js +@@ -50,7 +50,7 @@ module.exports = { + */ + + timeout: function timeout(req, res, options) { +- if(options.timeout) { ++ if(options.timeout || options.timeout === 0) { + req.socket.setTimeout(options.timeout); + } + }, +@@ -134,7 +134,7 @@ module.exports = { + + // allow outgoing socket to timeout so that we could + // show an error page at the initial request +- if(options.proxyTimeout) { ++ if(options.proxyTimeout || options.proxyTimeout === 0) { + proxyReq.setTimeout(options.proxyTimeout, function() { + proxyReq.abort(); + }); diff --git a/src/main/context-handler.ts b/src/main/context-handler.ts index 3abd97ea26..265a3e8132 100644 --- a/src/main/context-handler.ts +++ b/src/main/context-handler.ts @@ -102,12 +102,15 @@ export class ContextHandler { } } - public async getApiTarget() { - if (this.apiTarget) { return this.apiTarget } + public async getApiTarget(timeout: number) { + if (this.apiTarget) { + this.apiTarget.timeout = timeout + return this.apiTarget + } this.apiTarget = { changeOrigin: true, - timeout: 30000, + timeout: timeout, headers: { "Host": this.clusterUrl.hostname }, diff --git a/src/main/proxy.ts b/src/main/proxy.ts index 1db0ae2aa2..a57f0bba3e 100644 --- a/src/main/proxy.ts +++ b/src/main/proxy.ts @@ -130,7 +130,8 @@ export class LensProxy { if (req.url.startsWith("/api-kube/")) { delete req.headers.authorization req.url = req.url.replace("/api-kube", "") - return await contextHandler.getApiTarget() + const timeout = req.url.includes("watch=") ? 0 : 30000 + return await contextHandler.getApiTarget(timeout) } }