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

Crash when creating two tabs from within a batch script launched in the same terminal window #10328

Open
kaetemi opened this issue Jun 4, 2021 · 1 comment
Assignees
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Milestone

Comments

@kaetemi
Copy link

kaetemi commented Jun 4, 2021

Windows Terminal version (or Windows build number)

1.8.1444

Other Software

No response

Steps to reproduce

Crash when creating two tabs from within a batch script launched in the same terminal window.

Create the following files.

test1.bat:

wt -w test -d . -p "Command Prompt" test2.bat

test2.bat:

wt -w test -d . -p "Command Prompt" test3.bat
wt -w test -d . -p "Command Prompt" test3.bat

test3.bat:

echo Test
pause

There should be no window named "test" at first.

Double click on test1.bat.

Expected Behavior

A window with two tabs showing the "Test" output.

Actual Behavior

Terminal crashes as it attempts to launch the additional tab.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jun 4, 2021
@zadjii-msft
Copy link
Member

Huh, so what's going on here.

wt.exe is a WINDOWS subsystem application. So when cmd.exe launches that process, it doesn't wait for it to finish to return - it immediately moves on to the next command. So launching test1.bat will spawn a conhost running cmd, and that'll launch wt.exe, then find the end of test1.bat, exit cmd, then conhost will immediately exit.

Now, a first WT is launched, and it runs cmd.exe to process test2.bat. That wt window is named "test". That window now spawns cmd.exe to run test2.bat. Same deal, cmd starts, launches wt.exe, launches wt.exe, then exits. Now here's the tricky part - cmd is faster at running those commands than wt is at starting. So the cmd running in the first WT.exe window exits before either of the other wt.exe's spawn. That results in the first WT.exe exiting immediately, because the child process has exited.

This can be visualized easier by adding a sleep 5 to the end of test2.bat. If you do that, the subsequent tabs will open correctly.

Now we've gotten into a weird edge case - both these subsequent wt.exe's are launching at about the same time. I actually found that it was totally possible for the monarch to assign both these windows the name "test", which is NOT GOOD. That also popped open a post-mortem windbg for me, but that didn't actually end up breaking into anything? I wonder if it was attached to a COM thread that we just ate the exception from and kept going.

I'm gonna re-purpose this issue to tracking down whatever allowed both windows to have the name "test", and preventing that in the future, since this is a great test case.

@ future me: I put these scripts in %~%\bin

@zadjii-msft zadjii-msft added Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Jul 7, 2021
@zadjii-msft zadjii-msft added this to the Terminal v2.0 milestone Jul 7, 2021
@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Jul 7, 2021
@DHowett DHowett removed the Needs-Tag-Fix Doesn't match tag requirements label Jul 7, 2021
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label Jul 7, 2021
@zadjii-msft zadjii-msft modified the milestones: Terminal v2.0, 22H2 Jan 4, 2022
@zadjii-msft zadjii-msft modified the milestones: 22H2, Backlog Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

3 participants