1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Do not timeout watch requests (#273)

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-04-19 17:48:14 +03:00 committed by GitHub
parent 799482b3c4
commit ac552087d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -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<number> {

View File

@ -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)
}
}