diff --git a/src/node/cli.ts b/src/node/cli.ts index 7e4674eaa052..fc0f7bb413a8 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -52,6 +52,7 @@ export interface UserProvidedCodeArgs { "disable-workspace-trust"?: boolean "disable-getting-started-override"?: boolean "disable-proxy"?: boolean + "reconnection-grace-time"?: string "session-socket"?: string "cookie-suffix"?: string "link-protection-trusted-domains"?: string[] @@ -315,6 +316,12 @@ export const options: Options> = { type: "number", description: "Timeout in seconds to wait before shutting down when idle.", }, + "reconnection-grace-time": { + type: "string", + description: + "Override the reconnection grace time in seconds. Clients who disconnect for longer than this duration will need to \n" + + "reload the window. Defaults to 10800 (3 hours).", + }, } export const optionDescriptions = (opts: Partial>> = options): string[] => { @@ -631,6 +638,10 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config args["github-auth"] = process.env.GITHUB_TOKEN } + if (process.env.CS_RECONNECTION_GRACE_TIME) { + args["reconnection-grace-time"] = process.env.CS_RECONNECTION_GRACE_TIME + } + if (process.env.CODE_SERVER_IDLE_TIMEOUT_SECONDS) { if (isNaN(Number(process.env.CODE_SERVER_IDLE_TIMEOUT_SECONDS))) { logger.info("CODE_SERVER_IDLE_TIMEOUT_SECONDS must be a number") diff --git a/test/unit/node/cli.test.ts b/test/unit/node/cli.test.ts index 668a3c55776c..2962d25176aa 100644 --- a/test/unit/node/cli.test.ts +++ b/test/unit/node/cli.test.ts @@ -47,6 +47,7 @@ describe("parser", () => { delete process.env.PASSWORD delete process.env.CS_DISABLE_FILE_DOWNLOADS delete process.env.CS_DISABLE_GETTING_STARTED_OVERRIDE + delete process.env.CS_RECONNECTION_GRACE_TIME delete process.env.VSCODE_PROXY_URI delete process.env.CS_DISABLE_PROXY console.log = jest.fn() @@ -114,6 +115,8 @@ describe("parser", () => { ["--session-socket", "/tmp/override-code-server-ipc-socket"], + ["--reconnection-grace-time", "86400"], + ["--host", "0.0.0.0"], "4", "--", @@ -150,6 +153,7 @@ describe("parser", () => { version: true, "bind-addr": "192.169.0.1:8080", "session-socket": "/tmp/override-code-server-ipc-socket", + "reconnection-grace-time": "86400", "abs-proxy-base-path": "/codeserver/app1", "skip-auth-preflight": true, }) @@ -456,6 +460,19 @@ describe("parser", () => { }) }) + it("should use env var CS_RECONNECTION_GRACE_TIME", async () => { + process.env.CS_RECONNECTION_GRACE_TIME = "86400" + const args = parse([]) + expect(args).toEqual({}) + + const defaultArgs = await setDefaults(args) + expect(defaultArgs).toEqual({ + ...defaults, + "reconnection-grace-time": "86400", + }) + delete process.env.CS_RECONNECTION_GRACE_TIME + }) + it("should error if password passed in", () => { expect(() => parse(["--password", "supersecret123"])).toThrowError( "--password can only be set in the config file or passed in via $PASSWORD",