From ac552087d500b98abbb685e8c700b7bf52da7b9e Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Sun, 19 Apr 2020 17:48:14 +0300 Subject: [PATCH] Do not timeout watch requests (#273) Signed-off-by: Lauri Nevala --- src/main/context-handler.ts | 20 ++++++++++++++------ src/main/proxy.ts | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/context-handler.ts b/src/main/context-handler.ts index 3abd97ea26..431f8c450a 100644 --- a/src/main/context-handler.ts +++ b/src/main/context-handler.ts @@ -102,12 +102,22 @@ export class ContextHandler { } } - public async getApiTarget() { - if (this.apiTarget) { return this.apiTarget } + public async getApiTarget(isWatchRequest = false) { + if (this.apiTarget && !isWatchRequest) { + return this.apiTarget + } + const timeout = isWatchRequest ? 4 * 60 * 60 * 1000 : 30000 // 4 hours for watch request, 30 seconds for the rest + const apiTarget = await this.newApiTarget(timeout) + if (!isWatchRequest) { + this.apiTarget = apiTarget + } + return apiTarget + } - this.apiTarget = { + protected async newApiTarget(timeout: number) { + return { changeOrigin: true, - timeout: 30000, + timeout: timeout, headers: { "Host": this.clusterUrl.hostname }, @@ -118,8 +128,6 @@ export class ContextHandler { path: this.clusterUrl.path }, } - - return this.apiTarget } protected async resolveProxyPort(): Promise { diff --git a/src/main/proxy.ts b/src/main/proxy.ts index 1db0ae2aa2..ff998d79dd 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 isWatchRequest = req.url.includes("watch=") + return await contextHandler.getApiTarget(isWatchRequest) } }