Skip to content
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

[JetBrains] Avoid shutting down terminals when closing the client #15527

Merged

Conversation

felladrin
Copy link
Contributor

@felladrin felladrin commented Dec 29, 2022

Description

This PR changes the following:

  • Avoid shutting down terminals when closing JetBrains Client.
  • Open terminals for each Gitpod Task Terminal running and close them when JetBrains Client gest closed. We need to do this because clicking "Disconnect" is different from clicking "X" button from JetBrains Client Window [1]. Now the terminals are behaving the same as in VS Code.
  • Replace the use of application.executeOnPooledThread (thread) with lifetime.launch (coroutine).

About the changes

Making the GitpodTerminalService class extend Disposable opens doors for us to use the defineNestedLifetime() method inside the class.
This method creates a LifetimeDefinition that is automatically terminated whenever the class is disposed.
GitpodTerminalService is created when a Controller Client connects and disposed when the client disconnects.
The LifetimeDefinition also allow us to launch coroutines (via launch method), and these coroutines are automatically terminated when the lifetime terminates.
This allows us to rely on the lifetime life-cycle to avoid running something in case the Controller Client disconnects.
For example: If we do the following, <some_task> won't be executed if the lifetime is terminated within 5 seconds after the coroutine is launched:

lifetime.launch {
    delay(5000)
    <some_task>
}

We currently have no way to know if a terminal widget was closed manually by the user or if it was closed due to the user closing JetBrains Client [1], so this allows us to prevent <some_task> [shutting down Gitpod Task Terminals, in our case] from running if JetBrains client has been closed. Gitpod Task Terminals are only shut down if the user clicks the "X" button in the terminal widget.

Related Issue(s)

How to test

  1. Open the preview environment of this PR and select Stable IntelliJ IDEA as your editor.
  2. Start a new workspace from Gitpod's Repository, which has 5 terminals opened when it starts.
  3. Close JetBrains Client by clicking "X" button.
  4. Reconnect to the workspace and confirm if all the terminals remain open. Repeat it 3 times to ensure they never get closed unless you click "X" button on the terminal widget. (You can also use gp tasks list to know if Gitpod Terminals are in the "running" state)

Release Notes

Fixed an issue which caused Gitpod Terminals to be terminated when closing JetBrains Client.

Werft options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

@werft-gitpod-dev-com

This comment was marked as resolved.

@felladrin felladrin changed the title [JetBrains] Avoid shutting down terminals when disconnecting the client [JetBrains] Avoid shutting down terminals when closing the client Dec 30, 2022
@felladrin felladrin force-pushed the felladrin/avoid-shutting-down-terminals-when-exiting-client branch from a1f5fbf to bb392d2 Compare December 30, 2022 15:38
@felladrin

This comment was marked as resolved.

@felladrin felladrin force-pushed the felladrin/avoid-shutting-down-terminals-when-exiting-client branch from bb392d2 to bdd2bb6 Compare December 30, 2022 16:52
@roboquat roboquat added size/M and removed size/S labels Dec 30, 2022
@felladrin

This comment was marked as resolved.

@felladrin felladrin marked this pull request as ready for review December 30, 2022 17:16
@felladrin felladrin requested a review from a team December 30, 2022 17:16
@andreafalzetti
Copy link
Contributor

andreafalzetti commented Jan 3, 2023

/werft run recreate-preview

👍 started the job as gitpod-build-felladrin-avoid-shutting-down-terminals-whena.5
(with .werft/ from main)

Copy link
Contributor

@andreafalzetti andreafalzetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and tested, works as expected ✅

/hold

Unhold when you're ready

Instead, close the widgets and reopen then when the client joins again.
@felladrin felladrin force-pushed the felladrin/avoid-shutting-down-terminals-when-exiting-client branch from bdd2bb6 to bfdd9c3 Compare January 3, 2023 15:48
@roboquat roboquat merged commit 72c01b0 into main Jan 3, 2023
@roboquat roboquat deleted the felladrin/avoid-shutting-down-terminals-when-exiting-client branch January 3, 2023 16:15
@roboquat roboquat added deployed: IDE IDE change is running in production deployed Change is completely running in production labels Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: IDE IDE change is running in production deployed Change is completely running in production editor: jetbrains release-note size/M team: IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JetBrains] Task should be stopped when closing terminal tab
4 participants