eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.87k stars 2.49k forks source link

Creating a terminal in a basic (Hello World) Theia app hangs the app #12733

Open jcortell68 opened 1 year ago

jcortell68 commented 1 year ago

Bug Description:

A basic Theia app hangs when you try to create a terminal on Windows...but only if you launch the app via the VS Code launch configuration.

git clone -b master https://github.com/jcortell68/theiasandbox
cd theiasandbox
yarn
yarn rebuild:electron
code .
  1. In VS Code, launch the Theia app using Start Electron Backend. Don't start a debug session; use Run Without Debugging
  2. Create a terminal via Terminal > New Terminal Note that a terminal seems to appear (without a prompt) but the Theia app/UI is completely hung at that point.

Interestingly, the problem does not happen if you launch the app from the terminal using yarn start:electron

Additional Information

vince-fugnitto commented 1 year ago

It seems to work fine both when I generate a new hello-world app, or yours (I am on Linux) however. Could it be caused by https://github.com/eclipse-theia/theia/issues/12734 instead?

jcortell68 commented 1 year ago

12734 is a separate issue that I opened; I very much doubt they are related (other than they might both be Windows-only issues)

Let me try on Linux. This could be a Windows-only issue.

jcortell68 commented 1 year ago

Yeah. Works fine for me on Linux. We'll need someone else to try on Windows and see if it's a "me" issue or a general one.

vladarama commented 1 year ago

@jcortell68 I just tried reproducing the bug on Windows and everything seems to work fine. Demo: terminal hanging

jcortell68 commented 1 year ago

@vladarama Thanks. That got me thinking. I tried to reproduce the issue, but this time closed the workspace in the Theia app. Sure enough, it works now. I tried opening a different workspace. Still works. So I'm guessing there was something funky in the workspace that Theia was opening earlier. Unfortunately, I don't remember what directory that was. But needless to say, we can close this ticket. Thanks guys!

jcortell68 commented 1 year ago

@vince-fugnitto BTW, I retried 12734 and that one is still reproducible. So confirmed that issue and this one are unrelated.

jcortell68 commented 1 year ago

Uh oh. The plot thickens. The hang suddenly and unexpectedly started happening for me, and without being able to workaround it by closing the workspace. After a lot of head-scratching, I realized what was going on. The problem reproduced for me only when I launch the app via the VS Code's launch configuration (Start Electron Backend). Note that I launch it using Run Without Debugging

If I launch the app at the terminal using yarn start:electron, then the problem doesn't reproduce.

@vladarama Can you try using the launch configuration? Curious to see if you reproduce the issue that way.

vladarama commented 1 year ago

Yeah, I can confirm the bug is present on Windows when launching electron from VS Code's launch config. Demo: terminal hanging

jcortell68 commented 1 year ago

Thanks for confirming! I'll adjust the ticket title and description and reopen it

jcortell68 commented 1 year ago

@vladarama Quick side question: what tool do you use to create your GIF screen recordings?

vladarama commented 1 year ago

@jcortell68 I use LICEcap for the GIF recordings: https://www.cockos.com/licecap/

vince-fugnitto commented 1 year ago

@jcortell68 I believe the issue is pretty specific to the theia-extension-generator (might even be fixed by https://github.com/eclipse-theia/generator-theia-extension/pull/173).

Also note that the .vscode/launch.json you have in your repository does not work (@vladarama had to modify https://github.com/jcortell68/theiasandbox/commit/6ed8dd5a7ff3b54f8e3a7e1a7c956cd45868f3cf), and the steps you highlighted to reproduce are incomplete (yarn is not sufficient before starting to debug with start without debugging).

jcortell68 commented 1 year ago

@vince-fugnitto Yeah. I just realized the issues with the setup a little while ago. I tried building from a fresh git clone and ran into them. I'm sorting that out now. But I don't think the issue is fixed by the pull request you mention, as I have that change in other branches in my repo and I think I can reproduce the problem there. Anyway, let me clean this all up and I'll post and update here shortly

jcortell68 commented 1 year ago

OK. I've pushed a new commit which resolves all the setup issues. I also added a missing step in the description that only made itself obvious in a clean environment (I added yarn rebuild:electron)

I git clone'd to a new location and tested the reproducibility steps. Everything went smooth, and the problem still reproduces.

I can also confirm it reproduces only on Windows.

Gerd-Augsburg commented 1 year ago

I have a very different environment, but the exact same Problem. I build the Docker Container from: https://github.com/eclipse-theia/theia-blueprint If i try to open a terminal in the browser, the backend hangs. No Error, just not responsive anymore.

If i restart the backend and open with a browser that "remembers" the open terminal tab i see a warning in the Logs: "terminal WARN Couldn't attach - can't find terminal with id: -1" and the backend immediately hangs again.

Not sure if realated or complete different Problem.

jcortell68 commented 1 year ago

@Gerd-Augsburg That second scenario also happens for me in the Electron case. I.e., if when I launch the app, it already has a terminal open, then the app hangs right away. I suspect we are running into the same underlying problem.

Gerd-Augsburg commented 1 year ago

An update: The underlying problem might be the same (i assume it can't open a new tty) but the reason for it on my side is Docker. Local without container it works fine and running the container as a pod in a kubernetes cluster works too. Only Docker run doesn't work. If someone knows the docker setting i am missing, it would be nice to know, but here is not the place for docker questions. So for this thread my problem is not existent any more.

martin-fleck-at commented 1 year ago

So I debugged into this on Windows and I believe we are a victim of this bug: https://github.com/microsoft/node-pty/issues/532. If I manually pause before line

const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, c => this._$onProcessExit(c));

during debugging then everything works. It seems that there is something not ready yet to connect but I couldn't find any stack trace or error.

I tried several versions to see if the problem might be resolved in any of them:

Unfortunately, for me they all have the same issue so I think we may need to wait for this bug to be fixed on the node-pty side or we could try to artifically introduce some delay somehow.

jcortell68 commented 1 year ago

Nice sleuthing. It's unfortunate that node-pty ticket was opened 18 months ago and has had no meaningful activity. I guess waiting it out is reasonable given that it's a bit of a specialized scenario (hang happens on Windows only, only if launched via VS Code launch config, only when opening a terminal). I guess if we see more people pile on to this ticket, we can consider an ugly sleep hack. Thanks for investigating this!