Skip to content

Commit ada3489

Browse files
authored
feat: expose --reconnection-grace-time CLI flag (#7678)
* feat: expose --reconnection-grace-time CLI flag Pass through VS Code Server's --reconnection-grace-time argument, allowing users to configure how long the server waits for a disconnected client to reconnect before cleaning up the session. This is useful for users whose client machines sleep overnight, causing the default 3-hour grace period to expire and forcing a "Reload Window" on wake. The flag can also be set via CODE_SERVER_RECONNECTION_GRACE_TIME env var or in config.yaml.
1 parent 4d615f1 commit ada3489

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/FAQ.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server)
2323
- [What is the healthz endpoint?](#what-is-the-healthz-endpoint)
2424
- [What is the heartbeat file?](#what-is-the-heartbeat-file)
25+
- [How do I change the reconnection grace time?](#how-do-i-change-the-reconnection-grace-time)
2526
- [How do I change the password?](#how-do-i-change-the-password)
2627
- [Can I store my password hashed?](#can-i-store-my-password-hashed)
2728
- [Is multi-tenancy possible?](#is-multi-tenancy-possible)
@@ -326,6 +327,16 @@ If you want to shutdown code-server if there hasn't been an active connection
326327
after a predetermined amount of time, you can use the --idle-timeout-seconds flag
327328
or set an `CODE_SERVER_IDLE_TIMEOUT_SECONDS` environment variable.
328329

330+
## How do I change the reconnection grace time?
331+
332+
Pass `--reconnection-grace-time <seconds>` to `code-server`, set
333+
`CODE_SERVER_RECONNECTION_GRACE_TIME=<seconds>`, or add
334+
`reconnection-grace-time: <seconds>` to
335+
`~/.config/code-server/config.yaml`.
336+
337+
The default is `10800` (3 hours). If a client stays disconnected longer than
338+
this, it must reload the window.
339+
329340
## How do I change the password?
330341

331342
Edit the `password` field in the code-server config file at

src/node/cli.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface UserProvidedCodeArgs {
5252
"disable-workspace-trust"?: boolean
5353
"disable-getting-started-override"?: boolean
5454
"disable-proxy"?: boolean
55+
"reconnection-grace-time"?: string
5556
"session-socket"?: string
5657
"cookie-suffix"?: string
5758
"link-protection-trusted-domains"?: string[]
@@ -315,6 +316,12 @@ export const options: Options<Required<UserProvidedArgs>> = {
315316
type: "number",
316317
description: "Timeout in seconds to wait before shutting down when idle.",
317318
},
319+
"reconnection-grace-time": {
320+
type: "string",
321+
description:
322+
"Override the reconnection grace time in seconds. Clients who disconnect for longer than this duration will need to \n" +
323+
"reload the window. Defaults to 10800 (3 hours).",
324+
},
318325
}
319326

320327
export const optionDescriptions = (opts: Partial<Options<Required<UserProvidedArgs>>> = options): string[] => {
@@ -632,6 +639,10 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
632639
args["github-auth"] = process.env.GITHUB_TOKEN
633640
}
634641

642+
if (process.env.CODE_SERVER_RECONNECTION_GRACE_TIME) {
643+
args["reconnection-grace-time"] = process.env.CODE_SERVER_RECONNECTION_GRACE_TIME
644+
}
645+
635646
if (process.env.CODE_SERVER_IDLE_TIMEOUT_SECONDS) {
636647
if (isNaN(Number(process.env.CODE_SERVER_IDLE_TIMEOUT_SECONDS))) {
637648
logger.info("CODE_SERVER_IDLE_TIMEOUT_SECONDS must be a number")

test/unit/node/cli.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe("parser", () => {
4848
delete process.env.PASSWORD
4949
delete process.env.CS_DISABLE_FILE_DOWNLOADS
5050
delete process.env.CS_DISABLE_GETTING_STARTED_OVERRIDE
51+
delete process.env.CODE_SERVER_RECONNECTION_GRACE_TIME
5152
delete process.env.VSCODE_PROXY_URI
5253
delete process.env.CS_DISABLE_PROXY
5354
console.log = jest.fn()
@@ -115,6 +116,8 @@ describe("parser", () => {
115116

116117
["--session-socket", "/tmp/override-code-server-ipc-socket"],
117118

119+
["--reconnection-grace-time", "86400"],
120+
118121
["--host", "0.0.0.0"],
119122
"4",
120123
"--",
@@ -151,6 +154,7 @@ describe("parser", () => {
151154
version: true,
152155
"bind-addr": "192.169.0.1:8080",
153156
"session-socket": "/tmp/override-code-server-ipc-socket",
157+
"reconnection-grace-time": "86400",
154158
"abs-proxy-base-path": "/codeserver/app1",
155159
"skip-auth-preflight": true,
156160
})
@@ -457,6 +461,19 @@ describe("parser", () => {
457461
})
458462
})
459463

464+
it("should use env var CODE_SERVER_RECONNECTION_GRACE_TIME for reconnection grace time", async () => {
465+
process.env.CODE_SERVER_RECONNECTION_GRACE_TIME = "86400"
466+
const args = parse([])
467+
expect(args).toEqual({})
468+
469+
const defaultArgs = await setDefaults(args)
470+
expect(defaultArgs).toEqual({
471+
...defaults,
472+
"reconnection-grace-time": "86400",
473+
})
474+
delete process.env.CODE_SERVER_RECONNECTION_GRACE_TIME
475+
})
476+
460477
it("should error if password passed in", () => {
461478
expect(() => parse(["--password", "supersecret123"])).toThrowError(
462479
"--password can only be set in the config file or passed in via $PASSWORD",

0 commit comments

Comments
 (0)