Skip to content

Add optional idle timeout shutdown #7177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gaberudy
Copy link

I did this for my needs but realized there is a closed issue (not implemented) that is requesting the same thing.

Through the idle-timeout arg or IDLE_TIMEOUT environment variable, after the specified number of minutes since the heartbeat was last refreshed is detected, the code-server process shuts down. When run as the single process of a docker container, this just stops the container.

Fixes #1636

@gskifstad
Copy link

hi! our team would love this feature as well. I see there is a stray merge conflict causing linter errors, but otherwise, is there anything blocking this PR?

@code-asher
Copy link
Member

Yeah happy to merge this in if the conflicts and below are addressed.

I think the heart counting inactivity and directly exiting the process is more than it should be doing. Maybe we could refactor so the heart has an onChange event that is called when the state changes to either active or inactive? Then we can tie it all together in entry.ts.

// could propagate the event through `server` or maybe we could just pass the `heart` itself back
server.onChange((state) => {
  if (state === "active") {
    clearTimeout(timer)
  } else if (args["idle-timeout"]) {
    timer = setTimeout(() => {
      logger.warn(`Idle timeout of ${args["idle-timeout"]} minutes exceeded`)
      wrapper.exit();
    }, args["idle-timeout"] * 60 * 1000);
  }
})

Something like that.

I think if we have the flag as idle-timeout we might want to have it in seconds by default and allow m or h or s suffixes? Or change the flag to idle-timeout-minutes or something.

One other thing, we should check the parseInt for NaN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --idle-timeout to shutdown code-server when there isn't an active connection
3 participants